Thanks! I’m glad to hear my ramblings have been of some use. Yeah, things evolve over the years. I never do sit still on any one technique, whether that is good or bad I don’t know.
On the first point, I no longer hide the first header. This always kind of bothered me anyway because it means data in the content area that is really honestly meta-data, not data. The document ID now goes into the Keywords field in all of my files.
I’ve also switched, as you noted, from relying on simple file merging to handle the problem where lots of smaller notes are meant to be part of one larger summary; mainly because I don’t physically merge things any more. I don’t find this terribly useful given how I record information, and prefer a “personal web” of inter-linked documents.
To get this into the MMD system, I decided to write my own script, and then adjust the helper scripts to add my script into the pipe that processes files, rather than try to add these features to the Perl scripts themselves. The easiest place to add this is in the Support.pm file. I added a variable at the top, accessible to all of the sub-routines, with [b]parse_links.rb |[/b]
as its data, and then insert that variable wherever I saw a line like:
open (MultiMarkdown, "| cd \"$MMDPath\"; bin/MultiMarkdown.pl | bin/$SmartyPants $xslt $out");
Altering it to:
open (MultiMarkdown, "| cd \"$MMDPath\"; $custom_parsing bin/MultiMarkdown.pl | bin/$SmartyPants $xslt $out");
The key is to get it in before the main MultiMarkdown.pl script runs, as its job is to turn my shorthand into full MMD syntax.
Yes, in fact the above CSS snippet would do that with a little alteration. The first part of that is the “selector”. To hide all h1 elements indiscriminately, you would type this into the CSS file instead:
h1 { display:none; }
If you wanted to hide several levels:
h1, h2 { display:none; }
For the script itself, I have slimmed it down a bit. There were a lot of other things in it that are just personal additions. Note there is also support for a [b]<^filename^>[/b]
notation, which just tacks on the root archive folder path. This is useful in the CSS field, for instance.
CSS: <^/machinery/css/article.css^>
Will expand out to a full file URL, which will cause the resulting HTML file to be styled according to the CSS stylesheet—and again preserve the advantage of not hard-linking to anything. So long as I keep the ‘machinery’ folder within the root archive folder, I’ll have friendly CSS displays when I view my files.
What I still have yet to do is find a way of MMD processing something when you click on the link. Of course, in any browser if you are viewing the HTML and click on a cross-reference, it takes you to the actual .md file, something the browser is not capable of handling—so it comes out as plain text. I toyed with the idea of “pre-rendering” anything a document links to and stashing them in a cache folder as HTML and then linking to that, but this could result in massive render times for larger documents with lots of links to other large documents—and how far should the chain go, what about the documents they link to?
Fortunately that is just a mild irritation. If I really need to see the linked document in HTML instead of MMD, I can just render that one too.
So to install the script, copy and paste the below into a file and save that into your MMD/bin folder. After doing that, change its executable bit to on, and edit the file’s configuration section to match your setup.
The script assumes you have a text file called [b]invalid_id.txt[/b]
in the root archive. This is nothing fancy; just a text file that says the link you clicked on could not be associated with any file ID. So if you typo the ID, you’ll know what’s wrong. If you want to put this file some place else, just change line 18 to reflect that.
You can test the script prior to fully integrating it, by doing something like this on the command line:
cat input_file.md | ruby parse_links.rb > output_file.md
That assumes both the script and test file are in the same spot, of course. The product should be a valid MMD file with no custom mark-up. This is what gets invisibly passed to the full MultiMarkdown.pl script, once integrated.
Detailed technical notes on the actual syntax usage are in the comments at the top of the script.
One other thing of note: it doesn’t ignore verbatim or code blocks. It wouldn’t be too difficult to add that, but I’ve never had a need for putting cross-reference syntax into a code span.
[code]#!/usr/bin/ruby
require ‘find’
START CONFIGURATION
-----------------------------------------------------------------
home_dir = ENV[‘HOME’] ? ENV[‘HOME’] : ‘/Users/USERNAME’
$pre = ‘file://localhost’
$icfsBase = home_dir + ‘/PATH/TO/ARCHIVE_ROOT/FILES’
$arkBase = home_dir + ‘/PATH/TO/ARCHIVE_ROOT’
$error_file = $arkBase + ‘invalid_id.txt’
-----------------------------------------------------------------
END CONFIGURATION
Pre-load full ICFS list
icfsList =
Find.find($icfsBase) { |f| icfsList.push(f) }
def findICFS(strid, fileList)
res = fileList.find { |f| f =~ //#{strid}/ }
if res
return res.gsub(/\s/, ‘%20’)
else
return $error_file
end
end
Regular expressions
fileLink = /<^([^^]+)^>/
embeddedID = /([[^]]+])(<|\D{0,2}(\d{8}).?|>)/
bareID = /<|(\D{0,2})(\d{8}).?|>/
referredLink = /^([[^]]+]:\s)(<|\D{0,2}(\d{8}).*?|>)/
#inpt = File.open(‘test_data.txt’) { |fn| fn.readlines }
inpt = $stdin
process_input = inpt.readlines
process_input.each do |line|
case line
when referredLink
line.sub!(referredLink, $1 + $pre + findICFS($2, icfsList))
redo
when fileLink
# Fix file links
line.sub!(fileLink, $pre + $arkBase + $1)
redo
when embeddedID
# Find link embedded in MMD link
line.sub!(embeddedID, ‘\1(’ + $pre + findICFS($2, icfsList) + ‘)’)
redo
when bareID
if $1 != ‘’
ind = $1
else
ind = ‘id’
end
line.sub!(bareID, “[#{ind}” + ‘\2](’ + $pre + findICFS($2, icfsList) + ‘)’)
redo
else
print line
next
end
end[/code]