template generator

With templates I can get rid of some repetetive stuff, but I stil have to write my b-logs in both html and gemtext, which I don't want to. Therefore I made few scripts to generate those templates for me from markdown-like markup langue.

the markup language

# h1
## h2
### h3

this will
all be
on single line
because I like to have my
text manually wrapped under 80 chars

new paragraf

**bold**        ignored by gemtext
//italic//      ignored by gemtext
__underlined__  ignored by gemtext

* unordered
* list
* !

[link name](link address)

links [can](also://be.inline)!

`quoted text`

 ```
   <pre> like
      +---------------+
      |block          |
      |for source code|
      |and ascii art  |
      +---------------+
   </pre>
 ```

Also files are named as path to its outcome on site wth extra number before name, or name two times if it is not part of series. This is so that it can be sorted in correct order. This file is called

b-log.ruby.site-gen.020:template-generator

generation script

gen-templates.rb

This script will read all 'b-log' starting files and genrate coresponding .template files for both html and gemtext. It will add coresponding header/footer template words and previous/next links, but it will not actually translate text to html/gemtext yet. Instead it will add complex TO_HTML and TO_GEMTEXT words with link to original b-log file.

conversion scripts

to-gemtext.rb to-html.rb

Nothing that interesting, just a bunch of regex. Converting to html was actually easier, because I did not have to care about putting paragrafs onto one line while keeping empty lines around other elements. Escape codes for regex replacements can only be put in single quoted string that does not support newline escape so that was funny. Also sometimes you want to put regex operations into empty while loop to count replacement outcome in next search.

# like this because I want to
# consume the added newline if next element
# is also link

while part.sub! /\n?[^\n\S]*\[(.+?)\]\((.+?)\)[^\n\S]*\n?/, "\n=> "+'\2 \1'+"\n"
end

Also since the script are called from backtick string, I return value through stdout with print. It is important to not use puts, for it adds newline that can break some stuff.