[TxMt] Re: New Bundle
Allan Odgaard
throw-away-1 at macromates.com
Tue Jan 24 17:59:56 UTC 2006
On 24/1/2006, at 10:08, Oliver Taylor wrote:
> [...] I've posted a new screencast that goes into much more detail
> regarding what I the bundle to be able to do. Grab it here: http://
> www.ollieman.net/files/screencast2.mp4
Ah okay -- so basically it's the conversion you want help with?
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).
But as for the conversion -- you seem to have defined a very simple
format for the screenplays which can be converted to HTML simply by
doing line-by-line substitutions.
Perl (for example) can do a substitution (replacement) with this
command:
s/«regular expression»/«replacement»/«options»
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 (…)).
Normally you would loop over each line, and do a transformation to
test for each type of construct, but perl has a -p option which
basically does that for you, so we can settle with the substitutions.
Looking at your example file (but not the language grammar) I arrived
with the script and substitutions shown below (it may look a little
complex, though mostly because of the escaping of slashes):
#!/usr/bin/perl -p
s/&/&/g;
s/</</g;
s/\/\/(.*)\/\//<!--$1-->/g;
s/^[A-Z].*:$/<h4>$&<\/h4>/;
s/^EXT\. .*$/<h2>$&<\/h2>/;
s/^\w.*$/<p>$&<\/p>/;
s/^(\t{4})([^\t].*)$/<dl>$1<dt>$2<\/dt>/;
s/^(\t{3})([^\t].*)$/$1<dd class="parenthetical">$2<\/dd>/;
s/^(\t{2})([^\t].*)$/$1<dd>$2<\/dd><\/dl>/;
s/^(\t{10})([^\t].*:)$/$1<h3>$2<\/h3>/;
You can either save this script and run it with a file as stdin and
have it output the result to stdout, or you can paste it directly
into the bundle editor (as a new command) and set input to selection
or document, and output to e.g. replace selection, like shown here:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TextMateScreenSnapz107.png
Type: application/applefile
Size: 36852 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20060124/7db83da9/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TextMateScreenSnapz107.png
Type: image/png
Size: 96732 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20060124/7db83da9/attachment-0001.png>
-------------- next part --------------
Actually, after taking the grab, I added two lines to the script to
escape & and < (since these are reserved HTML characters).
> The ultimate goal is to end up with a PDF which contains text that
> conforms to the Studio Format [...]
I would suggest using htmldoc [1] for the HTML -> PDF conversion.
If you need further help, let me know (as I have no idea what your
shell/programming skills are).
[1]: http://www.htmldoc.org/
More information about the textmate
mailing list