diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2015-03-12 19:43:41 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 15:00:39 +0100 |
commit | e2a72ac7ba55f5d0a26e4cbe57d6be3a0e85b751 (patch) | |
tree | 142e9f1c0386cfb5461696cc7cfce8fdd35e5b1a /packages/gitbook-markdown/lib | |
parent | 2196afddd60f6a9e050cad7baf4bf6d6935f6769 (diff) | |
download | gitbook-e2a72ac7ba55f5d0a26e4cbe57d6be3a0e85b751.zip gitbook-e2a72ac7ba55f5d0a26e4cbe57d6be3a0e85b751.tar.gz gitbook-e2a72ac7ba55f5d0a26e4cbe57d6be3a0e85b751.tar.bz2 |
Add inline annotation and improve code layout
Diffstat (limited to 'packages/gitbook-markdown/lib')
-rw-r--r-- | packages/gitbook-markdown/lib/annotate_blocks.js (renamed from packages/gitbook-markdown/lib/annotate.js) | 2 | ||||
-rw-r--r-- | packages/gitbook-markdown/lib/annotate_engine.js | 2 | ||||
-rw-r--r-- | packages/gitbook-markdown/lib/annotate_inline.js | 40 |
3 files changed, 42 insertions, 2 deletions
diff --git a/packages/gitbook-markdown/lib/annotate.js b/packages/gitbook-markdown/lib/annotate_blocks.js index 34e5d90..032194b 100644 --- a/packages/gitbook-markdown/lib/annotate.js +++ b/packages/gitbook-markdown/lib/annotate_blocks.js @@ -35,7 +35,7 @@ var ruleMap = { 'nptable': 'table', 'lheading': 'heading', 'newline': 'space', -} +}; function annotate(src) { return engine(src, rules, ruleTypes, ruleMap); diff --git a/packages/gitbook-markdown/lib/annotate_engine.js b/packages/gitbook-markdown/lib/annotate_engine.js index 1feea47..181ee30 100644 --- a/packages/gitbook-markdown/lib/annotate_engine.js +++ b/packages/gitbook-markdown/lib/annotate_engine.js @@ -37,7 +37,7 @@ function annotateEngine(src, rules, ruleTypes, ruleMap) { src = src.substring(raw.length); } - return tokens + return tokens; } module.exports = annotateEngine; diff --git a/packages/gitbook-markdown/lib/annotate_inline.js b/packages/gitbook-markdown/lib/annotate_inline.js new file mode 100644 index 0000000..d2e8f89 --- /dev/null +++ b/packages/gitbook-markdown/lib/annotate_inline.js @@ -0,0 +1,40 @@ +var engine = require('./annotate_engine'); + +// Pulled from "kramed.InlineLexer.rules.gfm" +var rules = { + escape: /^\\([\\`*{}\[\]()#$+\-.!_>~|])/, + autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, + url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/, + tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/, + link: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\(\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*\)/, + reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\s*\[([^\]]*)\]/, + nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, + reffn: /^!?\[\^((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]/, + strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, + em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, + code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/, + br: /^ {2,}\n(?!\s*$)/, + del: /^~~(?=\S)([\s\S]*?\S)~~/, + text: /^[\s\S]+?(?=[\\<!\[_*`$~]|https?:\/\/| {2,}\n|$)/, + math: /^\$\$\s*([\s\S]*?[^\$])\s*\$\$(?!\$)/, + //_inside: /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/, + //_href: /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/ +}; + +// List of all the regexes we want to run +var ruleTypes = [ +'escape', 'autolink', 'url', 'tag', 'link', 'reflink', +'nolink', 'reffn', 'strong', 'em', 'code', 'br', +'del', 'text', 'math' +]; + +// Mapping if rule type is different from token type +var ruleMap = { + +}; + +function annotate(src) { + return engine(src, rules, ruleTypes, ruleMap); +} + +module.exports = annotate; |