Skip to content

Commit

Permalink
Added support to do insert-statement server-side when possible. Exper…
Browse files Browse the repository at this point in the history
…imental!
  • Loading branch information
breakin committed Jul 12, 2018
1 parent 2969114 commit 5012aeb
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
19 changes: 18 additions & 1 deletion convert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
hljs = require('highlight.js')
fs = require('fs'); // file system

function local_file_handler(filename) {
var fn = 'docs/' + filename;
try {
var content = fs.readFileSync('docs/' + filename, 'utf8');

content = content.rp(/<!-- Markdeep: -->[^\n]+/g, function(match, filename) {
return '\n'
})

console.log(' Successfully inserted ' + fn);
return content;
} catch (err) {
console.log(' Failed to insert ' + fn + ', error ' + err);
return undefined;
}
}

function entag(tag, content, attribs) {
return '<' + tag + (attribs ? ' ' + attribs : '') + '>' + content + '</' + tag + '>';
}
Expand Down Expand Up @@ -49,7 +66,7 @@ function convert(from_file, to_file, online_file, use_math = true) {
}

css = window.markdeep.stylesheet();
content = window.markdeep.format(data, false);
content = window.markdeep.format(data, false, local_file_handler);

// Construct final html
str = "<html>\n\t<head>\n";
Expand Down
2 changes: 0 additions & 2 deletions docs/features.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,4 @@
likewise for pre tags. Fortunately, it is pretty hard to imagine a case where you would want
nested code tags.

<!-- Markdeep: --><script src="markdeep.min.js"></script>

<!-- Markdeep: --><script src="markdeep.original.js"></script>
56 changes: 51 additions & 5 deletions docs/features_offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -3453,7 +3453,57 @@

</p><p>

(insert example.md.html here)
<strong class="asterisk">Example</strong>

</p><p>

Welcome to Markdeep. It's the simple
way to write plain text with <em class="underscore">style</em>.

</p><p>

<svg class="diagram" xmlns="http://www.w3.org/2000/svg" version="1.1" height="128" width="288" style="margin:0 auto 0 auto;"><g transform="translate(8,16 )">
<path d="M 8,16 L 8,48 " style="fill:none;"/>
<path d="M 72,16 L 72,48 " style="fill:none;"/>
<path d="M 88,40 L 88,64 " style="fill:none;"/>
<path d="M 176,32 L 176,64 " style="fill:none;"/>
<path d="M 8,16 L 72,16 " style="fill:none;"/>
<path d="M 216,16 L 248,16 " style="fill:none;"/>
<path d="M 72,32 L 104,32 " style="fill:none;"/>
<path d="M 168,32 L 192,32 " style="fill:none;"/>
<path d="M 8,48 L 72,48 " style="fill:none;"/>
<path d="M 216,48 L 248,48 " style="fill:none;"/>
<path d="M 104,80 L 160,80 " style="fill:none;"/>
<path d="M 100,56 L 124,8 " style="fill:none;"/>
<path d="M 156,56 L 180,8 " style="fill:none;"/>
<path d="M 216,16 C 199.2,16 200,32 200,32 " style="fill:none;"/>
<path d="M 248,16 C 264.8,16 264,32 264,32 " style="fill:none;"/>
<path d="M 216,48 C 199.2,48 200,32 200,32 " style="fill:none;"/>
<path d="M 248,48 C 264.8,48 264,32 264,32 " style="fill:none;"/>
<path d="M 104,80 C 87.2,80 88,64 88,64 " style="fill:none;"/>
<path d="M 160,80 C 176.8,80 176,64 176,64 " style="fill:none;"/>
<path d="M 124,8 L 180,8 " style="fill:none;"/>
<path d="M 100,56 L 156,56 " style="fill:none;"/>
<polygon points="200,32 188,26.4 188,37.6 " style="stroke:none" transform="rotate(0,192,32 )"/>
<polygon points="112,32 100,26.4 100,37.6 " style="stroke:none" transform="rotate(0,104,32 )"/>
<polygon points="96,40 84,34.4 84,45.6 " style="stroke:none" transform="rotate(270,88,40 )"/>
<g transform="translate(0,0)"><text text-anchor="middle" x="24" y="36">W</text><text text-anchor="middle" x="32" y="36">r</text><text text-anchor="middle" x="40" y="36">i</text><text text-anchor="middle" x="48" y="36">t</text><text text-anchor="middle" x="56" y="36">e</text><text text-anchor="middle" x="128" y="36">E</text><text text-anchor="middle" x="136" y="36">d</text><text text-anchor="middle" x="144" y="36">i</text><text text-anchor="middle" x="152" y="36">t</text><text text-anchor="middle" x="216" y="36">S</text><text text-anchor="middle" x="224" y="36">h</text><text text-anchor="middle" x="232" y="36">a</text><text text-anchor="middle" x="240" y="36">r</text><text text-anchor="middle" x="248" y="36">e</text></g></g></svg>

</p><p>

<ol start=1>
<li class="number">Write a text document
</li>
<li class="number">Add the Markdeep line at the end
</li>
<li class="number">Save with file extension <code>.md.html</code>
</li>
<li class="number">Double-click to view</li></ol>

</p><p>

Learn more at
<a href="https://casual-effects.com/markdeep" class="url">https://casual-effects.com/markdeep</a>

</p>
<a class="target" name="differencesfromothermarkdown">&nbsp;</a><a class="target" name="toc12">&nbsp;</a><h1>Differences from Other Markdown</h1>
Expand Down Expand Up @@ -3543,8 +3593,4 @@
that appear in the document, you cannot nest a code tag inside of another code tag, and
likewise for pre tags. Fortunately, it is pretty hard to imagine a case where you would want
nested code tags.

</p><p>

<script src="markdeep.min.js"></script>
</p></span></body></html>
17 changes: 16 additions & 1 deletion markdeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,21 @@ function isolated(preSpaces, postSpaces) {
Set elementMode = false if processing a whole document instead of an internal node.
*/
function markdeepToHTML(str, elementMode) {
function markdeepToHTML(str, elementMode, local_file_handler = undefined) {
// If a local file handler is specified, resolve '(insert src here)' directly when possible'
// Only expected to be used when run as script via node.js
if (local_file_handler !== undefined) {
str = str.rp(/(?:^|\s)\(insert[ \t]+(\S+\.\S*)[ \t]+here\)\s/g, function(match, filename) {
var content = local_file_handler(filename);
if (content === undefined) {
// Leave unchanged!
return match;
} else {
return content;
}
});
}

// Map names to the number used for end notes, in the order
// encountered in the text.
var endNoteTable = {}, endNoteCount = 0;
Expand Down Expand Up @@ -4472,6 +4486,7 @@ if (! window.alreadyProcessedMarkdeep) {
};

source = source.rp(/(?:^|\s)\(insert[ \t]+(\S+\.\S*)[ \t]+here\)\s/g, function(match, src) {

if (numIncludeChildrenLeft === 0) {
// This is the first child observed. Prepare to receive messages from the
// embedded children.
Expand Down

0 comments on commit 5012aeb

Please sign in to comment.