From a8427c9423dd93ca7ce10161ff67d3b191389f5e Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Sun, 10 Dec 2017 04:49:24 +0000 Subject: [PATCH] feat(completeHTMLOutput): add option to output a complete HTML document --- dist/showdown.js | Bin 167671 -> 168544 bytes dist/showdown.js.map | Bin 416270 -> 418747 bytes dist/showdown.min.js | Bin 96432 -> 96927 bytes dist/showdown.min.js.map | Bin 73664 -> 74030 bytes src/converter.js | 3 +++ src/options.js | 5 +++++ src/subParsers/completeHTMLOutput.js | 17 +++++++++++++++++ test/features/completeHTMLOutput/simple.html | 14 ++++++++++++++ test/features/completeHTMLOutput/simple.md | 7 +++++++ test/node/testsuite.features.js | 13 ++++++++++++- 10 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/subParsers/completeHTMLOutput.js create mode 100644 test/features/completeHTMLOutput/simple.html create mode 100644 test/features/completeHTMLOutput/simple.md diff --git a/dist/showdown.js b/dist/showdown.js index 1e9fb75201100c39f860e19385c4d01bd2a30ac9..bb806080153459d83ff3bc0234deefcd226ccb3a 100644 GIT binary patch delta 458 zcmex9m+Qe2t_c!Mh6Wp@jtftg=VB8~&d)8#Ni9kB2=VptFD)r3ogBbt5&&kE6e}bu zz~mJ&N^)})Qu32ab5rw5bQCi4l5&^~8A#`*mHhPn*%=E-4CcEty Jt}v?a0ssOfq>%ss delta 36 ucmV+<0NelIqzd<)3Xm8AFgdXr#}k8^6t|ib0W*iUaGU|XIk!640VcW;CJvea diff --git a/dist/showdown.js.map b/dist/showdown.js.map index 2697701878525e1757d1f3ab785b225f97cf5e54..52d42695ad773777dcdd3d8a67e75b06e874d604 100644 GIT binary patch delta 969 zcmZ`%T}V@580LJR-&)7)sEy@>?DHq*@@Mm+=tphSnh}aK%@8K+=#Dzw&enEDKZ1!u z2AN7<_(l*ILeP!O43=2n=pyOL>Y|%26e6L5^xmX%HbxM3_dMVGzR&x<&-+cjG%dd~ z#hhGjPcRVjONw-{y}79+s)V8n+u-sRo!pmV<}wOwIQs%~PbRycG*<>NO9;%WAIOg2-aa zu?dXBP3PGMTRw!IBLiET=b8OFKSnKaYT=gN!pbA9+fn{+>srRMwTC>L?dDT8w*3V& z3n)W(*5POfIl=LRtI`eDI~;@c@U#k5!>$GEVfD1yv}yqJGoy%yl}4Nq-~P$v8n9J# zLe6LOBtFNX+pR!3G?uQuHi25W6OfodRuD$83A)PAopf;9gY94|M_KTDNF8z3sj9AX zgtg2O2;Ng)Vpn;fo7^GrNGKERF+^Z9p$;)JshXoXl+F-fb_xlMJ`>=6E;@7v?ju=NU8g760GU8&PYs7TWvg7zx`KlKKCq5(-(DyUEH@khNrxsQ5k zv{0R=LPL`1t@BV(_Nt^i=)I{DMeK`!xP<9=M*_z?5*e$Ho5PaqmBRm(SJfkmDn*06 zYEDQDD?ZUreZ5ramuN7g_<}O^MW`f;-G0dnJDsF(uYEQ;$q}&KB^hy(o0QamwU0Dq zrx!~9a9AHD=U~1~m$jF~u0uy*C`wB9sI%%yHTBGXbIJj?TTU6Efq|agD^IzL>a>tG>5_($4ynLQ%c&yWP^y%$FHmMtnK_x5j;ke_#W3=TROI}-KorDc MT|>O)5&4+-1DS_XA^-pY delta 172 zcmV;d08{_F#~F^a8L&nHvv2|2BeQuXxdQ`eOhlKVKmsI_z!(abkb(mgmyo{!3YTCs z0uz(K76g;+1s8*_Dz~pH0fEDpPjCYYli*|ulkiCdw@~i^5)=b9VMdqntOF#M@T&q8 zmmvEA1ebvO0S1>Z6axyE5Rn28x4;7e!BLZ-S_+fE848o&w+ffQ<^c|eZ&?DjZ&?Ef aZih9<1GhEE1jw4VqhkdhJh$qh1<}DF4nqb2 diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 8b0db7268f1798acd65151e61a5b419b57ce0b5a..bf11a0d8cb326051813b571fabff34030b70533f 100644 GIT binary patch delta 388 zcmdn+k#+u8)(PTFh6WoY75RmAlJj#5a#BlDJwkka{7Xv;N=qhx;FS-6FpCuu6<`V! zGD>oD6jJh&OLJ56N^}%5^OAE)Q!?|?6%uSfQg#VCAXaK(id}+2VqOZ6la!xQ3FMR{ zrWZGB@^9DVXS~6znQrT;S6rGDkXTflTBM-_Gag~TlBPzwPQH%g_WweRlHx*`3Z@&D zGHPHGmsezzuE$ibmz0{8UzDn(ldj{ay+ArQwFKzZ43MKrY?VSo z+;lCJ?119>U=INqV86uVscWa}l@w*>YG`UJfuy0rKy{!X09rA9vI3(7Hpi_kV^rKO Jp~X1E4*+g;h1>uD delta 36 scmbRLm36~M)(PTF29_Ho75SUb@^3%O&v=}9`+i|Yaq;c!I*c>?004Xpk^lez diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index b4e6a8d163a481060c33158f778903b9e25c1e96..2cf99027dd446d00586ec5aefcac1850dba9231a 100644 GIT binary patch delta 5210 zcmb7IdvH|M8J`nCc9D<(0Rl;oM-WODb~n3u)jE3axp!|a%epL^-DFWa#*prNlTG#+ zwX`$sIGwRN^^Dz4XIiUH>o{5;U1#EqDC!@5ibFe7hmJ@TX+=atMF|2!zwewI2n?OE z|K#pD=R4o?_dQNt+c)>wH|9Qnpk~R?NP09ioEz@#^KJL%bEElOb$`t>+T7e&JY6mH zZmp?4y{%#Xx_+wd>{e_e3T0Z1*@h?`vT2m<&MLMDrGvJ#hrbwT-8jN*UP`^p=A+c7 zir<>@GmvS`K`AvX9b2F!W90};UcpQ!w0Xh7*lc2U^bmnzaXQ-d9m^W zpCPIPA3q$8R0noONnJt(aXM(_ryiPQ4-c&06ICfqswjXOa11*6Z9&R9v?T87eL{_t zIQPe;G?VO#l{c+|xPH3=n(Q334N}^dQQ~QJ=d; zsO1QNCt^aJ-xl|vr8D|~rIJ4=r2~I7-Du~vp?!5T7s}wRoRX}*6WTiG#)5_v!$@ma ziW(Xk0Y|f4;=0B_7p4`sJ#uJsnc;yps$rzYh0}9v2tx=9ooXePSHX2mo8TS0-n^w7 z@6uq`WdS9nTLTZ<)!S_SKn8ALR5(!hFJ!+=IiVD*x8A;yESgczp#B7lS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|~MGCy`QiH`QkP9Of{5zmm0ohUj6vnjXQDnx4Pj0MX{kl%bua^%39Dc9Ncq6)2MILN%V!dTXV=!h= zFC(9tS2r&rF(=1ER%t{nR3I zBgyG2s)>cfb!#<=TPh-l;3_mcfNrWBp1rS{{H3}!U8!?m-e6kKn}}~0RC4MX)c}(=C8Mu46Kh@N zt0^Ib(7>qPYbNXdYkFG$k(qev@XH9l&ERtuzDyI$JNvAe{AO|OnD}h=_XzA;_0mf6 zya}3SjLBG1@2Mj@Nml=D9ci&tK2G3^Rg^0SI1-Et&N!LAzm{0m%Z`TzjE$lO0VhBu zwg_q6vWi%$a2?MN+j_<^J^S=~ZMgxiKXgE+~7gP?0N%mzCJKjIN0I92-Gu zjVdmE&1!N3nV$8oCYwo*jFB*Wcz`oJvL|#G1Sfp2y z4ZsDsJxwbP{dWyyoypi6n%0jskQQ@?+!o1WUvQ<`>CJ1%_IgkVkVN2f!|#zTnQJz_ zhMXfyvw%PRy)>$3n7*@-e5W#zQnO6IzmZHX#R!GJhej2cSl>jnm3Smd13-9yKufaO znI;lhwA?NJeUTsPiP=}0$+t;0xT2q*`TKf(Y$<8dZ*C#0O+X#|+n_6>r(4KIaN?aU YWF5)P9&91ElbRV-IJ~6WH;^y?4Rgl&?EnA( diff --git a/src/converter.js b/src/converter.js index eacf003..8325fda 100644 --- a/src/converter.js +++ b/src/converter.js @@ -314,6 +314,9 @@ showdown.Converter = function (converterOptions) { // attacklab: Restore tremas text = text.replace(/¨T/g, '¨'); + // render a complete html document instead of a partial if the option is enabled + text = showdown.subParser('completeHTMLOutput')(text, options, globals); + // Run output modifiers showdown.helper.forEach(outputModifiers, function (ext) { text = showdown.subParser('runExtension')(ext, text, options, globals); diff --git a/src/options.js b/src/options.js index fc4df19..c743c45 100644 --- a/src/options.js +++ b/src/options.js @@ -150,6 +150,11 @@ function getDefaultOpts (simple) { defaultValue: false, description: 'Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled, underscores no longer parses into `` and ``', type: 'boolean' + }, + completeHTMLOutput: { + defaultValue: false, + description: 'Outputs a complete html document, including ``, `` and `` tags', + type: 'boolean' } }; if (simple === false) { diff --git a/src/subParsers/completeHTMLOutput.js b/src/subParsers/completeHTMLOutput.js new file mode 100644 index 0000000..7b8c722 --- /dev/null +++ b/src/subParsers/completeHTMLOutput.js @@ -0,0 +1,17 @@ +/** + * Turn Markdown link shortcuts into XHTML tags. + */ +showdown.subParser('completeHTMLOutput', function (text, options, globals) { + 'use strict'; + + if (!options.completeHTMLOutput) { + return text; + } + + text = globals.converter._dispatch('completeHTMLOutput.before', text, options, globals); + + text = '\n\n\n\n\n' + text.trim() + '\n\n'; + + text = globals.converter._dispatch('completeHTMLOutput.after', text, options, globals); + return text; +}); diff --git a/test/features/completeHTMLOutput/simple.html b/test/features/completeHTMLOutput/simple.html new file mode 100644 index 0000000..62aa62a --- /dev/null +++ b/test/features/completeHTMLOutput/simple.html @@ -0,0 +1,14 @@ + + + + + +

This is a markdown file

+

Converted into a full HTML document

+
    +
  • this
  • +
  • is
  • +
  • awesome
  • +
+ + diff --git a/test/features/completeHTMLOutput/simple.md b/test/features/completeHTMLOutput/simple.md new file mode 100644 index 0000000..e35ed26 --- /dev/null +++ b/test/features/completeHTMLOutput/simple.md @@ -0,0 +1,7 @@ +This is a **markdown** file + +Converted into a full HTML document + + - this + - is + - awesome diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index a0d0194..a7ee7e8 100644 --- a/test/node/testsuite.features.js +++ b/test/node/testsuite.features.js @@ -14,7 +14,8 @@ var bootstrap = require('../bootstrap.js'), emojisSuite = bootstrap.getTestSuite('test/features/emojis/'), underlineSuite = bootstrap.getTestSuite('test/features/underline/'), literalMidWordUnderscoresSuite = bootstrap.getTestSuite('test/features/literalMidWordUnderscores/'), - literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/'); + literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/'), + completeHTMLOutputSuite = bootstrap.getTestSuite('test/features/completeHTMLOutput/'); describe('makeHtml() features testsuite', function () { 'use strict'; @@ -231,4 +232,14 @@ describe('makeHtml() features testsuite', function () { it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter)); } }); + + /** test completeHTMLOutput option **/ + describe('completeHTMLOutput option', function () { + var converter, + suite = completeHTMLOutputSuite; + for (var i = 0; i < suite.length; ++i) { + converter = new showdown.Converter({completeHTMLOutput: true}); + it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter)); + } + }); });