-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPublishtoProjectPages.m
87 lines (66 loc) · 2.07 KB
/
PublishtoProjectPages.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function PublishtoProjectPages(scriptfilename)
opts = struct('format','xml','outputDir','published','imageFormat','png');
filepath = publish(scriptfilename,opts);
fid = fopen(filepath);
Data = textscan(fid,'%s','Delimiter','\n','Whitespace','');
Data = Data{1};
fclose(fid);
fid = fopen(filepath);
Data2 = textscan(fid,'%s','Delimiter','\n');
Data2 = Data2{1};
fclose(fid);
for i = 1:length(Data)
currentline = Data{i};
currentline2 = Data2{i};
if size(currentline,2) > 0
if size(currentline2,2) > 0
if currentline2(1) == '<'
Data{i}=currentline2;
end
end
end
end
cd published
fileID = fopen('aligned.xml','w');
for i = 1:length(Data)
fprintf(fileID,'%s\n',Data{i});
end
fclose(fileID);
xslt('aligned.xml','\..\toprojectpages.xsl','firstpass.md');
fid = fopen('firstpass.md');
Data3 = textscan(fid,'%s','Delimiter','\n','Whitespace','');
Data3 = Data3{1};
fclose(fid);
for i = 1:length(Data3)
currentline3 = Data3{i};
if size(currentline3,2) > 5
if currentline3(1:4) == '<img'
startIndex = regexp(currentline3,'"');
imagename=currentline3(startIndex(1)+1:startIndex(2)-1);
fid = fopen(imagename,'rb');
bytes = fread(fid);
fclose(fid);
encoder = org.apache.commons.codec.binary.Base64;
base64string = char(encoder.encode(bytes))';
currentline3 = ['<img src="data:image/png;base64,',base64string,'" />'];
Data3{i} = currentline3;
end
end
end
daterightnow = datevec(datetime('today'));
newfilename = [num2str(daterightnow(1)),'-'];
if daterightnow(2) < 10
newfilename = [newfilename,'0',num2str(daterightnow(2)),'-'];
else
newfilename = [newfilename,num2str(daterightnow(2)),'-'];
end
if daterightnow(3) < 10
newfilename = [newfilename,'0',num2str(daterightnow(3)),'-matlabpost.md'];
else
newfilename = [newfilename,num2str(daterightnow(3)),'-matlabpost.md'];
end
fileID = fopen(newfilename,'w');
for i = 1:length(Data3)
fprintf(fileID,'%s\n',Data3{i});
end
fclose(fileID);