From 275ec64dd136ceee5ec7a8ad91cd99485c14892a Mon Sep 17 00:00:00 2001 From: kts Date: Fri, 28 Nov 2014 16:04:40 -0800 Subject: [PATCH] Small header check now must be at beginning of string without any spaces. Match text now surrounded by \Q and \E so the match is not read as regex. Lightly modified documentation --- documentation/kettext_define.ktx | 1 + documentation/kettext_history.ktx | 4 ++-- kettext.pl | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/documentation/kettext_define.ktx b/documentation/kettext_define.ktx index 77f2981..d30b51e 100644 --- a/documentation/kettext_define.ktx +++ b/documentation/kettext_define.ktx @@ -2,6 +2,7 @@ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, kettext... ```````````````````````````````` + * **is a markup language** * **is for the design-inclined programmer** * **is easy to write with** * **looks nice in a terminal** diff --git a/documentation/kettext_history.ktx b/documentation/kettext_history.ktx index 4082887..7a62738 100644 --- a/documentation/kettext_history.ktx +++ b/documentation/kettext_history.ktx @@ -3,12 +3,12 @@ A Brief History of kettext ```````````````````````````````` From a linguistics perspective, kettext is the formal definition of a more loose internal documentation/note format I've used for many of my projects. However, the reason it came to be a formal syntax is a bit more involved. -When I released the procedural generation library, [[proclib]].href(../proclib/), I wrote some brief documentation for it on its [[itch.io page]].href(http://kts_kettek.itch.io/proclib). Due to preferring self-hosting, I wanted to have the same documentation under my webserver as was on the itch.io page. However, this led to some formatting issues, as itch.io's HTML source output tended towards breakage when modifying lists and similar - it also meant that the original source would be itch.io. +When I released the procedural generation library, [[proclib]].href(proclib/), I wrote some brief documentation for it on its [[itch.io page]].href(http://kts_kettek.itch.io/proclib). Due to preferring self-hosting, I wanted to have the same documentation under my webserver as was on the itch.io page. However, this led to some formatting issues, as itch.io's HTML source output tended towards breakage when modifying lists and similar - it also meant that the original source would be itch.io. From this, I figured I would convert the documentation into a markup language and convert from that to both itch.io and my own page. However, after trying various markup languages, such as markdown and textile, I found them to be quite limiting when wanting to implement some HTML-centric options (such as class, name, and similar). As a result, I decided to format the source text into the documentation/note format that I had become accustomed to using. This meant that I would have to write a parser and converter -- something I did not initially feel inclined to do due to other projects. -However, given that I use this private format for internal documentation and my own notes, it seemed to be the logical thing to do. Furthermore, it gave me an excuse to pick up Perl(((after over 5 years!))) and actually learn to use regular expressions. +However, given that I use this private format for internal documentation and my own notes, it seemed to be the logical thing to do. Furthermore, it gave me an excuse to pick up Perl ((after over 5 years!)) and actually learn to use regular expressions. What was born from this was a codified version of my internal documentation format -- //kettext// -- and the accompanying parser/converter, **kettext.pl**. diff --git a/kettext.pl b/kettext.pl index ab6abcc..3acdbba 100755 --- a/kettext.pl +++ b/kettext.pl @@ -185,7 +185,7 @@ for (my $i = 0; $i <= $#lines; $i++) { } } # 3. check for small headers - if ($lines[$i] =~ m/(\S)\1{2,}/) { + if ($lines[$i] =~ m/^(\S)\1{2,}/) { my $size = $+[0]; my $match = substr($lines[$i], $-[0], $+[0]-$-[0]); my $post = substr($lines[$i], $+[0]); @@ -194,7 +194,7 @@ for (my $i = 0; $i <= $#lines; $i++) { # e.g., ==== header ==== # otherwise match if there is some text following # e.g., ==== header - if ($post =~ m/(\t*|\s*|)(.*)$match$/g) { + if ($post =~ m/(\t*|\s*|)(.*)\Q$match\E$/g) { if (%block) { push @elements, {%block}; %block=() } if ($2 =~ m/^(.*?)(\..*\))/) { push @elements, {