Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
function scrippetize(text) { var scrippet_pattern_string = '[\\[<]scrippet[\\]>]([^]*?)[\\[<]\\/scrippet[\\]>]'; var scrippet_pattern = new RegExp(scrippet_pattern_string, "i"); var scrippet_pattern_g = new RegExp(scrippet_pattern_string, "gi"); while (matches = scrippet_pattern_g.exec(text)) { var output = '<div class="scrippet">' + "\r\n" + matches[1].replace(/<[^>]*>/g, '') /* remove any tags Wordpress or Markdown may dump into the scrippet */ .replace(/\r/g, '') /* some basic character replacements to deal with bugs that Wordpress/Markdown introduce */ .replace(/&/g, '&') .replace(/\.{3}|É/g, '...') .replace(/\-{2}|Ñ|?/g, '--') .replace(/(INT|EXT|EST)([\.\-\s]+?)(.+?)([A-Za-z0-9\)\s\.])\n/g, '<p class="sceneheader">$1$2$3$4</p>' + "\r\n") /* Sceneheaders must start with INT or EXT */ .replace(/\n([^<>\na-z]*?:|FADE TO BLACK\.|FADE OUT\.|CUT TO BLACK\.)[\s]??\n/g, '<p class="transition">$1</p>' + "\r\n") /* Catches transitions -- Looks for a colon, with some hard coded exceptions that don't use colons. */ .replace(/\n([^<>\n]*?:[^\n]+?)\n/g, '<p class="action">$1</p>' + "\r\n") .replace(/\n{2}(([^a-z\n\:]+?[\.\?\,\s\!]*?)\n{2}){1,2}/g, "\n" + '<p class="action">$2</p>' + "\r\n") /* Catches multi-line action blocks -- looks for all caps without punctuation, then two Newlines -- This differentiates from character cues because Cues will only have a single break, then the dialogue/parenthetical. */ .replace(/\n([^<>a-z\s][^a-z:\!\?]*?[^a-z\(\.\!\?:,][\s]??)\n/g, '<p class="character">$1</p>') /* Catches character cues -- Looks for all caps, parenthesis (for O.S./V.O.), then a single newline. */ .replace(/(\([^<>]*?\)[\s]??)\n/g, '<p class="parenthetical">$1</p>') /* Catches parentheticals -- Just looks for text between parenthesis. */ .replace(/(<p class="character">.*<\/p>|<p class="parenthetical">.*<\/p>)\n{0,1}(.+?)\n/g, '$1<p class="dialogue">$2</p>' + "\r\n") /* Catches dialogue -- Must follow a character cue or parenthetical. */ .replace(/([^<>]*?)\n/g, '<p class="action">$1</p>' + "\r\n") /* Defaults */ .replace(/<p class="action">[\n\s]*?<\/p>/g, '') /* Hack - cleans up the mess the action regex is leaving behind.*/ .replace(/\n/g, '') /* hide newlines from live comments */ + '\r\n</div>'; text = text.replace(scrippet_pattern, output); } return text; }
This paste will be private.
From the Design Piracy series on my blog: