On Jan 24, 2006, at 10:02 AM, Allen wrote:
Ah okay -- so basically it's the conversion you want help with?
yes.
I assume it's because you are not familiar with any programming language (which I must say, your bundle is pretty impressive if you are not -- even if you are, it still is impressive -- do you mind I link to the intro screencast in the RSS feed as an example of behavioral patterns in TM? I can keep a local cache of the bundle if you're concerned about bandwidth).
I'd be glad to host the screencast, if bandwidth becomes a problem, I'll let you know. And yes, I know exactly zero about programming languages. The first time I used a regexp was for this bundle.
I would suggest using htmldoc [1] for the HTML -> PDF conversion.
I'll check it out.
So what you want is to make a regular expression to match each construct in your format, which you already did in the language grammar, and then as the replacement string you specify how it should be transformed. Here you can use $& to refer to the entire match and $1-$n for captures (stuff captured with (…)).
Okay, based on what you posted here before, I added a few things that were missing and synced these with the language def.
#!/usr/bin/perl -p
s/&/&/g; #ampersands s/</</g; #reserved for HTML s/>/&lgt;/g; #reserved for HTML - maybe this is unnecessary? s/^EXT..*$/<h2>$&</h2>/; #scene heading s/^INT..*$/<h2>$&</h2>/; #scene heading s/^I/E..*$/<h2>$&</h2>/; #scene heading s/^[A-Z].*-\s[A-Z].*/<h2>$&</h2>/; #arbitrary scene heading ending with a time s/^[A-Z].*-\s*$/<h2>$&</h2>/; #arbitrary scene heading NOT ending with a time s/^\w.*$/<p>$&</p>/; #paragraph s///(.*)///<!-- $1 -->/g; #comments s/*(.*)*/<em>$1</em>/; #italics s/^(\t{4})([^\t].*)$/<dl>$1<dt>$2</dt>/; #characters s/^(\t{3})([^\t].*)$/$1<dd class="parenthetical"> $2 </dd>/; #parenthetical s/^(\t{2})([^\t].*)$/$1<dd>$2</dd></dl>/; #dialogue s/^(\t{10})([^\t].*:)$/$1<h3>$2</h3>/; #transition (right) s/^[A-Z].*:\s*/<h4>$&</h4>/; # transition (left)
The only one that's not working properly is the last one. It's baffling to be because it's the same regexp as in the language.
If you need further help, let me know (as I have no idea what your shell/programming skills are).
I have no programming skills other that those I've already demonstrated. Zip
There are a few steps left in the process that need to be addressed. Next the HTML marked-up text (as generated by the above script) needs to be inserted into an actual HTML document with doctype declarations, CSS etc. And somehow (again, I have no idea how) it needs to be transfered to a PDF authoring environment (htmldoc or whatever).
Lastly, thank all of you. It's great to give something to a community and get so much back.
On 24/1/2006, at 21:26, Oliver Taylor wrote:
I would suggest using htmldoc [1] for the HTML -> PDF conversion.
I'll check it out.
It's easy to install with Darwin Ports (sudo port install htmldoc) but it seems that htmldoc do not use the documents style sheet, at least not in the DP version (and with the switches I used).
Prince seems to do, judging from Ben Jacksons blog: http:// www.unfitforprint.com/articles/2005/12/23/markdown2pdf-with-prince- xml-and-textmate
[...] s/^[A-Z].*:\s*/<h4>$&</h4>/; # transition (left)
The only one that's not working properly is the last one. It's baffling to be because it's the same regexp as in the language.
I think because your transitions are right-aligned? The ^ character is a “begin of line anchor”. So you would need to add \s+ after it (for 1 or more whitespaces)
[...] There are a few steps left in the process that need to be addressed. Next the HTML marked-up text (as generated by the above script) needs to be inserted into an actual HTML document with doctype declarations, CSS etc. And somehow (again, I have no idea how) it needs to be transfered to a PDF authoring environment (htmldoc or whatever).
I changed/added to the command to generate a full HTML document, open it in Safari, and then also convert it to PDF and open with Preview.
Change the output to HTML (or maybe discard).
It stores the resulting files in /tmp (using the basename of your current document).
In practice you could use Safari to “Print to PDF”, but that's tedious, if you do it a lot.
----------8<----------
# first figure out a name for the result NAME="${TM_FILENAME:-untitled}" BASENAME="${NAME%.*}" DST="/tmp/$BASENAME"
# everything we output within { … } is written to the HTML file via redirection (see line with the }) { # first output HTML header cat <<HEAD <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>$BASENAME</title> <style type="text/css" media="screen"> /* The styles listed here can be static, but these are no where near a final reference, hust a sample. */ body { font-family: Courier; font-size: 12pt ; } #contentwrapper { width: 6in; margin: 1in 1in 1in 1.5in; } dl { margin: 0 1.5in 0 1.5in; padding: 0; } dt { margin: 1em 0 0 1in; padding: 0; } dd { margin: 0; padding: 0; } dd.parenthetical { margin-left: .5in ; width: 1.5in; padding: 0; } h1,h2,h3,h4,h5,h6 { font-weight: normal; font-size: 12pt; margin-top: 1em; } h3 { text-align: right; margin: 0 1in 0 2in; } </style> </head> <body> <div id="contentwrapper"> HEAD
# then HTML body (converted from document) perl -pe ' s/&/&/g; #ampersands s/</</g; #reserved for HTML s/>/&lgt;/g; #reserved for HTML - maybe this is unnecessary? s/^EXT..*$/<h2>$&</h2>/; #scene heading s/^INT..*$/<h2>$&</h2>/; #scene heading s/^I/E..*$/<h2>$&</h2>/; #scene heading s/^[A-Z].*-\s[A-Z].*/<h2>$&</h2>/; #arbitrary scene heading ending with a time s/^[A-Z].*-\s*$/<h2>$&</h2>/; #arbitrary scene heading NOT ending with a time s/^\w.*$/<p>$&</p>/; #paragraph s///(.*)///<!-- $1 -->/g; #comments s/*(.*)*/<em>$1</em>/; #italics s/^(\t{4})([^\t].*)$/<dl>$1<dt>$2</dt>/; #characters s/^(\t{3})([^\t].*)$/$1<dd class="parenthetical"> $2 </dd>/; #parenthetical s/^(\t{2})([^\t].*)$/$1<dd>$2</dd></dl>/; #dialogue s/^(\t{10})([^\t].*:)$/$1<h3>$2</h3>/; #transition (right) s/^\s+[A-Z].*:\s*/<h4>$&</h4>/; # transition (left) '
# and finally HTML footer cat <<'TAIL' </div> <!-- contentwrapper --> </body> </html> TAIL } >"$DST.html"
# open the generated HTML file in Safari open -a Safari "$DST.html"
# convert to PDF with htmldoc and open in Preview require_cmd htmldoc htmldoc -f "$DST.pdf" --header "" --footer "" --webpage "$DST.html"|pre open -a Preview "$DST.pdf"