mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
14 lines
5.8 KiB
JavaScript
14 lines
5.8 KiB
JavaScript
|
// https://github.com/mattdaly/Fountain.js/
|
||
|
|
||
|
(function(){var d={title_page:/^((?:title|credit|author[s]?|source|notes|draft date|date|contact|copyright)\:)/gim,scene_heading:/^((?:\*{0,3}_?)?(?:(?:int|ext|est|i\/e)[. ]).+)|^(?:\.(?!\.+))(.+)/i,scene_number:/( *#(.+)# *)/,transition:/^((?:FADE (?:TO BLACK|OUT)|CUT TO BLACK)\.|.+ TO\:)|^(?:> *)(.+)/,dialogue:/^([A-Z*_]+[0-9A-Z (._\-')]*)(\^?)?(?:\n(?!\n+))([\s\S]+)/,parenthetical:/^(\(.+\))$/,action:/^(.+)/g,centered:/^(?:> *)(.+)(?: *<)(\n.+)*/g,section:/^(#+)(?: *)(.*)/,synopsis:/^(?:\=(?!\=+) *)(.*)/,
|
||
|
note:/^(?:\[{2}(?!\[+))(.+)(?:\]{2}(?!\[+))$/,note_inline:/(?:\[{2}(?!\[+))([\s\S]+?)(?:\]{2}(?!\[+))/g,boneyard:/(^\/\*|^\*\/)$/g,page_break:/^\={3,}$/,line_break:/^ {2}$/,emphasis:/(_|\*{1,3}|_\*{1,3}|\*{1,3}_)(.+)(_|\*{1,3}|_\*{1,3}|\*{1,3}_)/g,bold_italic_underline:/(_{1}\*{3}(?=.+\*{3}_{1})|\*{3}_{1}(?=.+_{1}\*{3}))(.+?)(\*{3}_{1}|_{1}\*{3})/g,bold_underline:/(_{1}\*{2}(?=.+\*{2}_{1})|\*{2}_{1}(?=.+_{1}\*{2}))(.+?)(\*{2}_{1}|_{1}\*{2})/g,italic_underline:/(?:_{1}\*{1}(?=.+\*{1}_{1})|\*{1}_{1}(?=.+_{1}\*{1}))(.+?)(\*{1}_{1}|_{1}\*{1})/g,
|
||
|
bold_italic:/(\*{3}(?=.+\*{3}))(.+?)(\*{3})/g,bold:/(\*{2}(?=.+\*{2}))(.+?)(\*{2})/g,italic:/(\*{1}(?=.+\*{1}))(.+?)(\*{1})/g,underline:/(_{1}(?=.+_{1}))(.+?)(_{1})/g,splitter:/\n{2,}/g,cleaner:/^\n+|\n+$/,standardizer:/\r\n|\r/g,whitespacer:/^\t+|^ {3,}/gm},n={note:"<\!-- $1 --\>",line_break:"<br />",bold_italic_underline:'<span class="bold italic underline">$2</span>',bold_underline:'<span class="bold underline">$2</span>',italic_underline:'<span class="italic underline">$2</span>',bold_italic:'<span class="bold italic">$2</span>',
|
||
|
bold:'<span class="bold">$2</span>',italic:'<span class="italic">$2</span>',underline:'<span class="underline">$2</span>',lexer:function(c){if(c){for(var j="underline,italic,bold,bold_italic,italic_underline,bold_underline,bold_italic_underline".split(","),k=j.length,g,b,c=c.replace(d.note_inline,n.note).replace(/\\\*/g,"[star]").replace(/\\_/g,"[underline]").replace(/\n/g,n.line_break);k--;)g=j[k],b=d[g],b.test(c)&&(c=c.replace(b,n[g]));return c.replace(/\[star\]/g,"*").replace(/\[underline\]/g,
|
||
|
"_").trim()}}},h=function(c,d){return h.parse(c,d)};h.parse=function(c,j,k){var g;void 0===k&&"function"===typeof j&&(k=j,j=void 0);for(var b=c.replace(d.boneyard,"\n$1\n").replace(d.standardizer,"\n").replace(d.cleaner,"").replace(d.whitespacer,"").split(d.splitter),f=b.length,e,a,l,i,h,m,c=[];f--;)if(e=b[f],d.title_page.test(e)){a=e.replace(d.title_page,"\n$1").split(d.splitter).reverse();i=0;for(h=a.length;i<h;i++)l=a[i].replace(d.cleaner,"").split(/\:\n*/),c.push({type:l[0].trim().toLowerCase().replace(" ",
|
||
|
"_"),text:l[1].trim()})}else if(a=e.match(d.scene_heading)){if(e=a[1]||a[2],e.indexOf(" ")!==e.length-2){if(a=e.match(d.scene_number))a=a[2],e=e.replace(d.scene_number,"");c.push({type:"scene_heading",text:e,scene_number:a||void 0})}}else if(a=e.match(d.centered))c.push({type:"centered",text:a[0].replace(/>|</g,"")});else if(a=e.match(d.transition))c.push({type:"transition",text:a[1]||a[2]});else if((a=e.match(d.dialogue))&&a[1].indexOf(" ")!==a[1].length-2){a[2]&&c.push({type:"dual_dialogue_end"});
|
||
|
c.push({type:"dialogue_end"});l=a[3].split(/(\(.+\))(?:\n+)/).reverse();i=0;for(h=l.length;i<h;i++)e=l[i],0<e.length&&c.push({type:d.parenthetical.test(e)?"parenthetical":"dialogue",text:e});c.push({type:"character",text:a[1].trim()});c.push({type:"dialogue_begin",dual:a[2]?"right":m?"left":void 0});m&&c.push({type:"dual_dialogue_begin"});m=a[2]?!0:!1}else(a=e.match(d.section))?c.push({type:"section",text:a[2],depth:a[1].length}):(a=e.match(d.synopsis))?c.push({type:"synopsis",text:a[1]}):(a=e.match(d.note))?
|
||
|
c.push({type:"note",text:a[1]}):(a=e.match(d.boneyard))?c.push({type:"/"===a[0][0]?"boneyard_begin":"boneyard_end"}):d.page_break.test(e)?c.push({type:"page_break"}):d.line_break.test(e)?c.push({type:"line_break"}):c.push({type:"action",text:e});m=c.length;f=[];for(a=[];m--;)switch(b=c[m],b.text=n.lexer(b.text),b.type){case "title":f.push("<h1>"+b.text+"</h1>");g=b.text.replace("<br />"," ").replace(/<(?:.|\n)*?>/g,"");break;case "credit":f.push('<p class="credit">'+b.text+"</p>");break;case "author":f.push('<p class="authors">'+
|
||
|
b.text+"</p>");break;case "authors":f.push('<p class="authors">'+b.text+"</p>");break;case "source":f.push('<p class="source">'+b.text+"</p>");break;case "notes":f.push('<p class="notes">'+b.text+"</p>");break;case "draft_date":f.push('<p class="draft-date">'+b.text+"</p>");break;case "date":f.push('<p class="date">'+b.text+"</p>");break;case "contact":f.push('<p class="contact">'+b.text+"</p>");break;case "copyright":f.push('<p class="copyright">'+b.text+"</p>");break;case "scene_heading":a.push("<h3"+
|
||
|
(b.scene_number?' id="'+b.scene_number+'">':">")+b.text+"</h3>");break;case "transition":a.push("<h2>"+b.text+"</h2>");break;case "dual_dialogue_begin":a.push('<div class="dual-dialogue">');break;case "dialogue_begin":a.push('<div class="dialogue'+(b.dual?" "+b.dual:"")+'">');break;case "character":a.push("<h4>"+b.text+"</h4>");break;case "parenthetical":a.push('<p class="parenthetical">'+b.text+"</p>");break;case "dialogue":a.push("<p>"+b.text+"</p>");break;case "dialogue_end":a.push("</div> ");
|
||
|
break;case "dual_dialogue_end":a.push("</div> ");break;case "section":a.push('<p class="section" data-depth="'+b.depth+'">'+b.text+"</p>");break;case "synopsis":a.push('<p class="synopsis">'+b.text+"</p>");break;case "note":a.push("<\!-- "+b.text+"--\>");break;case "boneyard_begin":a.push("<\!-- ");break;case "boneyard_end":a.push(" --\>");break;case "action":a.push("<p>"+b.text+"</p>");break;case "centered":a.push('<p class="centered">'+b.text+"</p>");break;case "page_break":a.push("<hr />");break;
|
||
|
case "line_break":a.push("<br />")}g={title:g,html:{title_page:f.join(""),script:a.join("")},tokens:j?c.reverse():void 0};g="function"===typeof k?k(g):g;return g};"undefined"!==typeof module?module.exports=h:this.fountain=h}).call(this);
|