Skip to content

Commit a24101a

Browse files
committed
Upload
1 parent fcaf76a commit a24101a

File tree

2 files changed

+361
-0
lines changed

2 files changed

+361
-0
lines changed

PublishtoProjectPages.m

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

toprojectpages.xsl

+276
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
This is an XSL stylesheet which converts mscript XML files into HTML.
5+
Use the XSLT command to perform the conversion.
6+
7+
Copyright 1984-2012 The MathWorks, Inc.
8+
9+
Copyright (c) 2013, Kaelin Colclasure
10+
All rights reserved.
11+
12+
Redistribution and use in source and binary forms, with or without
13+
modification, are permitted provided that the following conditions are
14+
met:
15+
16+
* Redistributions of source code must retain the above copyright
17+
notice, this list of conditions and the following disclaimer.
18+
* Redistributions in binary form must reproduce the above copyright
19+
notice, this list of conditions and the following disclaimer in
20+
the documentation and/or other materials provided with the distribution
21+
* Neither the name of the Ohmware nor the names
22+
of its contributors may be used to endorse or promote products derived
23+
from this software without specific prior written permission.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
POSSIBILITY OF SUCH DAMAGE.
36+
37+
Modified Extensively for Project-Pages by Ahmet Cecen
38+
39+
-->
40+
41+
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#160;"> <!ENTITY reg "&#174;"> ]>
42+
<xsl:stylesheet
43+
version="1.0"
44+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
45+
xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"
46+
exclude-result-prefixes="mwsh">
47+
<xsl:output method="html"
48+
indent="no"/>
49+
<xsl:strip-space elements="mwsh:code"/>
50+
51+
<xsl:variable name="title">
52+
<xsl:variable name="dTitle" select="//steptitle[@style='document']"/>
53+
<xsl:choose>
54+
<xsl:when test="$dTitle"><xsl:value-of select="$dTitle"/></xsl:when>
55+
<xsl:otherwise><xsl:value-of select="mscript/m-file"/></xsl:otherwise>
56+
</xsl:choose>
57+
</xsl:variable>
58+
59+
60+
<xsl:template match="mscript">---
61+
layout: post
62+
title: New Matlab Script
63+
date: 2016-05-02
64+
author: Ahmet Cecen
65+
tags: matlab workflows
66+
subtitle: Some Short Description of the Script
67+
visualworkflow: true
68+
---
69+
{% if page.visualworkflow == true %}
70+
{% include workflowmatlab.html %}
71+
{% endif %}
72+
73+
74+
<xsl:comment>
75+
This HTML was auto-generated from MATLAB code.
76+
To make changes, update the MATLAB code and republish this document.
77+
</xsl:comment>
78+
79+
<xsl:call-template name="header"/>
80+
81+
<!-- Determine if the there should be an introduction section. -->
82+
<xsl:variable name="hasIntro" select="count(cell[@style = 'overview'])"/>
83+
84+
<!-- If there is an introduction, display it. -->
85+
<xsl:if test = "$hasIntro">
86+
<xsl:comment>introduction</xsl:comment>
87+
<xsl:apply-templates select="cell[1]/text"/>
88+
<xsl:comment>/introduction</xsl:comment>
89+
</xsl:if>
90+
91+
<xsl:variable name="body-cells" select="cell[not(@style = 'overview')]"/>
92+
93+
<!-- Include contents if there are titles for any subsections. -->
94+
<xsl:if test="count(cell/steptitle[not(@style = 'document')])">
95+
<xsl:call-template name="contents">
96+
<xsl:with-param name="body-cells" select="$body-cells"/>
97+
</xsl:call-template>
98+
</xsl:if>
99+
100+
<!-- Loop over each cell -->
101+
<xsl:for-each select="$body-cells">
102+
<!-- Title of cell -->
103+
<xsl:if test="steptitle">
104+
<xsl:variable name="headinglevel">
105+
<xsl:choose>
106+
<xsl:when test="steptitle[@style = 'document']">h1</xsl:when>
107+
<xsl:otherwise>h2</xsl:otherwise>
108+
</xsl:choose>
109+
</xsl:variable>
110+
<xsl:element name="{$headinglevel}">
111+
<xsl:apply-templates select="steptitle"/>
112+
<xsl:if test="not(steptitle[@style = 'document'])">
113+
<a>
114+
<xsl:attribute name="name">
115+
<xsl:value-of select="position()"/>
116+
</xsl:attribute>
117+
</a>
118+
</xsl:if>
119+
</xsl:element>
120+
</xsl:if>
121+
122+
<!-- Contents of each cell -->
123+
<xsl:apply-templates select="text"/>
124+
<xsl:apply-templates select="mcode-xmlized"/>
125+
<xsl:apply-templates select="mcodeoutput|img"/>
126+
127+
</xsl:for-each>
128+
129+
<xsl:call-template name="footer"/>
130+
131+
</xsl:template>
132+
133+
<!-- Header -->
134+
<xsl:template name="header">
135+
</xsl:template>
136+
137+
<!-- Footer -->
138+
<xsl:template name="footer">
139+
<xsl:text>&#xa;</xsl:text>
140+
<xsl:value-of select="copyright"/><br/>
141+
<a href="http://www.mathworks.com/products/matlab/" style="font-size: 0.7em">Published with MATLAB&reg; R<xsl:value-of select="release"/></a><br/>
142+
</xsl:template>
143+
144+
<!-- Contents -->
145+
<xsl:template name="contents">
146+
</xsl:template>
147+
148+
149+
<!-- HTML Tags in text sections -->
150+
<xsl:template match="p">
151+
<p><xsl:apply-templates/></p>
152+
</xsl:template>
153+
<xsl:template match="ul">
154+
<div><ul><xsl:apply-templates/></ul></div>
155+
</xsl:template>
156+
<xsl:template match="ol">
157+
<div><ol><xsl:apply-templates/></ol></div>
158+
</xsl:template>
159+
<xsl:template match="li">
160+
<li><xsl:apply-templates/></li>
161+
</xsl:template>
162+
<xsl:template match="pre">
163+
<xsl:choose>
164+
<xsl:when test="@class='error'">
165+
<pre class="error"><xsl:apply-templates/></pre>
166+
</xsl:when>
167+
<xsl:otherwise>
168+
<pre><xsl:apply-templates/></pre>
169+
</xsl:otherwise>
170+
</xsl:choose>
171+
</xsl:template>
172+
<xsl:template match="b">
173+
<b><xsl:apply-templates/></b>
174+
</xsl:template>
175+
<xsl:template match="i">
176+
<i><xsl:apply-templates/></i>
177+
</xsl:template>
178+
<xsl:template match="tt">
179+
<tt><xsl:apply-templates/></tt>
180+
</xsl:template>
181+
<xsl:template match="a">
182+
<a>
183+
<xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
184+
<xsl:apply-templates/>
185+
</a>
186+
</xsl:template>
187+
<xsl:template match="html">
188+
<xsl:value-of select="@text" disable-output-escaping="yes"/>
189+
</xsl:template>
190+
<xsl:template match="latex"/>
191+
192+
<!-- Detecting M-Code in Comments-->
193+
<xsl:template match="text/mcode-xmlized">
194+
<pre class="language-matlab"><xsl:apply-templates/><xsl:text><!-- g162495 -->
195+
</xsl:text></pre>
196+
</xsl:template>
197+
198+
<!-- Code input and output -->
199+
200+
<xsl:template match="mcode-xmlized">
201+
{% highlight matlab %}
202+
<xsl:apply-templates/>
203+
{% endhighlight %}
204+
</xsl:template>
205+
206+
<xsl:template match="mcodeoutput">
207+
<xsl:choose>
208+
<xsl:when test="concat(substring(.,0,7),substring(.,string-length(.)-7,7))='&lt;html&gt;&lt;/html&gt;'">
209+
<xsl:value-of select="substring(.,7,string-length(.)-14)" disable-output-escaping="yes"/>
210+
</xsl:when>
211+
<xsl:otherwise>
212+
{% highlight matlab %}
213+
<xsl:apply-templates/>
214+
{% endhighlight %}
215+
</xsl:otherwise>
216+
</xsl:choose>
217+
</xsl:template>
218+
219+
220+
<!-- Figure and model snapshots and equations -->
221+
<xsl:template match="img[@class='equation']">
222+
<xsl:text>&#xa;</xsl:text>
223+
<img>
224+
<xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
225+
</img>
226+
<xsl:text>&#xa;</xsl:text>
227+
</xsl:template>
228+
229+
<xsl:template match="img">
230+
<xsl:text>&#xa;</xsl:text>
231+
<img>
232+
<xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
233+
<xsl:text> </xsl:text>
234+
</img>
235+
<xsl:text>&#xa;</xsl:text>
236+
</xsl:template>
237+
238+
<!-- Stash original code in HTML for easy slurping later. -->
239+
240+
<xsl:template match="originalCode"></xsl:template>
241+
242+
<!-- Footer information -->
243+
244+
<xsl:template match="copyright">
245+
<xsl:value-of select="."/>
246+
</xsl:template>
247+
<xsl:template match="revision">
248+
<xsl:value-of select="."/>
249+
</xsl:template>
250+
251+
<!-- Search and replace -->
252+
<!-- From http://www.xml.com/lpt/a/2002/06/05/transforming.html -->
253+
254+
<xsl:template name="globalReplace">
255+
<xsl:param name="outputString"/>
256+
<xsl:param name="target"/>
257+
<xsl:param name="replacement"/>
258+
<xsl:choose>
259+
<xsl:when test="contains($outputString,$target)">
260+
<xsl:value-of select=
261+
"concat(substring-before($outputString,$target),$replacement)"/>
262+
<xsl:call-template name="globalReplace">
263+
<xsl:with-param name="outputString"
264+
select="substring-after($outputString,$target)"/>
265+
<xsl:with-param name="target" select="$target"/>
266+
<xsl:with-param name="replacement"
267+
select="$replacement"/>
268+
</xsl:call-template>
269+
</xsl:when>
270+
<xsl:otherwise>
271+
<xsl:value-of select="$outputString"/>
272+
</xsl:otherwise>
273+
</xsl:choose>
274+
</xsl:template>
275+
276+
</xsl:stylesheet>

0 commit comments

Comments
 (0)