From 5012aeb02fe5515716db0f268b3bb1175c19381b Mon Sep 17 00:00:00 2001 From: breakin Date: Thu, 12 Jul 2018 17:23:55 +0200 Subject: [PATCH] Added support to do insert-statement server-side when possible. Experimental! --- convert.js | 19 ++++++++++++- docs/features.md.html | 2 -- docs/features_offline.html | 56 ++++++++++++++++++++++++++++++++++---- markdeep.js | 17 +++++++++++- 4 files changed, 85 insertions(+), 9 deletions(-) diff --git a/convert.js b/convert.js index e0ff103..3a40d0f 100644 --- a/convert.js +++ b/convert.js @@ -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(/[^\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 + ''; } @@ -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 = "\n\t\n"; diff --git a/docs/features.md.html b/docs/features.md.html index 9d5880e..f9c68b4 100644 --- a/docs/features.md.html +++ b/docs/features.md.html @@ -1833,6 +1833,4 @@ likewise for pre tags. Fortunately, it is pretty hard to imagine a case where you would want nested code tags. - - diff --git a/docs/features_offline.html b/docs/features_offline.html index 0ae77c5..ce3e61a 100644 --- a/docs/features_offline.html +++ b/docs/features_offline.html @@ -3453,7 +3453,57 @@

- (insert example.md.html here) + Example + +

+ +Welcome to Markdeep. It's the simple +way to write plain text with style. + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + +WriteEditShare + +

+ +

    +
  1. Write a text document +
  2. +
  3. Add the Markdeep line at the end +
  4. +
  5. Save with file extension .md.html +
  6. +
  7. Double-click to view
+ +

+ +Learn more at +https://casual-effects.com/markdeep

  

Differences from Other Markdown

@@ -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. - -

- -

\ No newline at end of file diff --git a/markdeep.js b/markdeep.js index cd5e62c..419a232 100644 --- a/markdeep.js +++ b/markdeep.js @@ -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; @@ -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.