Reversing heading markup

95 views
Skip to first unread message

Helge Joao

unread,
Sep 4, 2008, 3:32:33 PM9/4/08
to wikidpad-devel
Would it be possible by changing some WikidPad-regexps to reverse the
markup of the headings?

IMHO the following (let's call it "reversed syntax") is superior the
(much more common) used in WikidPad. An example:
++++MAJOR HEADING
+++Heading 1
++minor heading 1
texttexttext
texttexttext
++minor heading 2
texttexttext
+++Heading 2
+++minor subheading of "Important Heading 2"
texttexttext

==Why is is superior?==
Imagine you have lots of "++"-headings in randomized order because you
just used them as titles for your notes about unrelated topics.
Now you want to introduce some higher structure. E. g. you want to
have a "private topics" and a "public topics" section.
With the above syntax you would only have to type:
+++private topics
+++public topics
and could begin to copy the "++"-headings with their paragraphs below
these headings.

With the current syntax you would have to type:
++private topics
++public topics
and change all subtopics to "+++"-headings.

This may sound like a minor annoyance... but with hundreds of
paragraphs and hundreds of changes back and forth in the structure
this gets very tedious. I used the reversed syntax in some wiki (I
forgot which one, it was a long time ago), but after getting used to
it, it was much better.

Does anybody (Michael?) see a way to do this?

Helge Joao

unread,
Sep 5, 2008, 4:18:56 AM9/5/08
to wikidpad-devel
Well, stupid me, that was easy enough. On first view this works good,
ask me if you are interested if I found problems later on.

Create WikiSyntax.py in your .WikidPadGlobals\user_extensions-
directory. (If you can't find it, you can also change it in C:\Program
Files\WikidPad\extensions\WikiSyntax.py , but that will be overwritten
on an WipidPad-update I think.)

Heading5RE = re.compile(ur"^\+{1}(?!\+) ?(?P<h5Content>" +
PlainCharacterPAT + ur"+?)\n",
re.DOTALL | re.UNICODE | re.MULTILINE)
Heading4RE = re.compile(ur"^\+{2}(?!\+) ?(?P<h4Content>" +
PlainCharacterPAT + ur"+?)\n",
re.DOTALL | re.UNICODE | re.MULTILINE)
Heading3RE = re.compile(ur"^\+{3}(?!\+) ?(?P<h3Content>" +
PlainCharacterPAT + ur"+?)\n",
re.DOTALL | re.UNICODE | re.MULTILINE)
Heading2RE = re.compile(ur"^\+{4}(?!\+) ?(?P<h2Content>" +
PlainCharacterPAT + ur"+?)\n",
re.DOTALL | re.UNICODE | re.MULTILINE)
Heading1RE = re.compile(ur"^\+{5}(?!\+) ?(?P<h1Content>" +
PlainCharacterPAT + ur"+?)\n",
re.DOTALL | re.UNICODE | re.MULTILINE)

Helge Joao

unread,
Sep 5, 2008, 4:22:54 AM9/5/08
to wikidpad-devel
Oh sorry, I forgot, if you create a new M:\.WikidPadGlobals
\user_extensions\WikiSyntax.py, this needs to go in the beginning of
the file:

import locale
import string

import pwiki.srePersistent as re
from pwiki.StringOps import mbcsDec

Michael Butscher

unread,
Sep 5, 2008, 5:15:40 AM9/5/08
to wikidpa...@googlegroups.com
Helge Joao wrote:
> Well, stupid me, that was easy enough. On first view this works good,
> ask me if you are interested if I found problems later on.
>
> Create WikiSyntax.py in your .WikidPadGlobals\user_extensions-
> directory.


One remark:

For users who started to use WikidPad with one of the later 1.9betas on
Windows, the directory ".WikidPadGlobals" may be named "WikidPadGlobals"
without leading dot.

Michael

Helge Joao

unread,
Sep 5, 2008, 6:04:34 AM9/5/08
to wikidpad-devel
Making it a little bit better: This will prevent minor headings from
having a larger font size than major headings.

Create the file ".WikidPadGlobals\user_extensions\Presentation.py"
containing:

from wx import Platform

if Platform == '__WXMSW__':
faces = { 'times': 'Times New Roman',
'mono' : 'Courier New',
'helv' : 'Arial',
'other': 'Comic Sans MS',
'size' : 10,
'heading4': 10,
'heading3': 10,
'heading2': 10,
'heading1': 10
}
else:
faces = { 'times': 'Times',
'mono' : 'Courier',
'helv' : 'Helvetica',
'other': 'new century schoolbook',
'size' : 10,
'heading4': 10,
'heading3': 10,
'heading2': 10,
'heading1': 10
}
#--- Cut. End. Don't copy this line.

I tried to make major headings have a larger font size, but
unfortunately something like the following does not work,

'heading4': 14,
'heading3': 13,
'heading2': 12,
'heading1': 11

Trying to set font-sizes for headings above 4 with this also does NOT
work.

Any hints very welcome!

Helge Joao

unread,
Sep 5, 2008, 8:22:13 AM9/5/08
to wikidpad-devel
Just in case somebody might be interested in future, here blurbs of my
further migration. Works only smoothly for headings up to five pluses.
Above that it looks a little ugly, but otherwise is fine.

Python-script to convert an original-sqlite-wiki to the reversed
heading syntax:

#!/usr/bin/python
# -*- coding: iso-8859-15 -*-

import os, os.path, string, re

filenameEndingDefault=".wiki"
startDirDefault=r"C:/Ho/vv/IriKopie/" # Put the directory here where
your *.wiki-files are. Slash at the end!!! (no backslash, not even on
MS Windows!)
def replaceStrings(s):
s=re.compile(r"^\+{2}(?!\+)").sub("²²²²²",s)
s=re.compile(r"^\+{3}(?!\+)").sub("²²²²",s)
s=re.compile(r"^\+{4}(?!\+)").sub("²²²",s)
s=re.compile(r"^\+{5}(?!\+)").sub("²²",s)
s=re.compile(r"^\+{6}(?!\+)").sub("²²( +heading)",s) # These should
not be needed. Just in case make it transparant.
s=re.compile(r"^\+{7}(?!\+)").sub("²²( 0+heading)",s)
s=re.compile(r"^\+{8}(?!\+)").sub("²²(-1+heading)",s)
s=re.compile(r"^\+{9}(?!\+)").sub("²²(-2+heading)",s)
s=re.compile(r"^\+{10}(?!\+)").sub("²²(-3+heading)",s)
s=string.replace(s,r"²",r"+")
return s

def replace(file):
temp = os.path.splitext(file)[0] + ".tmp"
try:
# remove old temp file, if any
os.remove(temp)
except os.error:
pass
fi = open(file)
fo = open(temp, "w")
for s in fi.readlines():
fo.write(replaceStrings(s))
fi.close()
fo.close()
os.remove(file)
os.rename(temp, file)

def
doit(startDir=startDirDefault,filenameEnding=filenameEndingDefault):
directories = [startDir]
while len(directories)>0:
directory = directories.pop()
for name in os.listdir(directory):
fullpath = os.path.join(directory,name)
if fullpath.endswith(filenameEnding) and
os.path.isfile(fullpath):
print fullpath # That's a file. Do
something with it.
replace(fullpath)
elif os.path.isdir(fullpath):
directories.append(fullpath) # It's a directory, store
it.

if __name__ == '__main__':
import sys
if len(sys.argv[1:])>0:
raise SystemExit, "Error: The target dir must be set inside the
python source. Command line args are forbidden."
doit()
print "replacer has finished"


Helge Joao

unread,
Sep 5, 2008, 8:24:28 AM9/5/08
to wikidpad-devel
For having bigger font-sizes for major headings I use the Internet
Explorer preview option in WikidPad with the following
"WikidPadGlobals\wikipreview.css":

body{
margin-left:20mm; /* This also moves the headings right, so no
relative change! */
font-family: Verdana; font-size: 100%}

/* Style of lists */
li {margin-left:-10mm;padding:.05 em;}
.wiki-name-ref { color: #888888; font-size: 75%;}
.parent-nodes { color: #888888; font-size: 75%;}
.property { color: #888888; font-size: 75%;}
.script { color: #888888; font-size: 75%;}
.todo {font-weight: bold;}
.url-link {}
.wiki-link {}

/* ############ Headings ############ */
/* h1,h2,h3 {...} funktioniert NICHT, wird überschrieben, wenn unten
nicht auch angegeben. Probiert.*/
/* "line-height" bringt nichts, weil es nur die minimale Höhe angibt.
*/
/* ############ 1 bis 4 werden benutzt ############ */
h1{margin-left: -20mm;font-size:240%; color:red ;font-weight:normal;
line-height:100%! important; padding:0;}
h2{margin-left: -15mm;font-size:220%; color:red ;font-weight:normal;
line-height:100%! important; padding:0;}
h3{margin-left: -10mm;font-size:180%; color:red ;font-weight:normal;
line-height:100%! important; padding:0;}
h4{margin-left: - 5mm;font-size:140%; color:red ;font-weight:normal;
line-height:100%! important; padding:0;}
/* ############ die folgenden werden NICHT benutzt ############ */
h5{margin-left:12mm;font-size:100%; color:red ;font-weight:normal;
line-height:100%! important; padding:0;margin-bottom: .6 em}
h6{font-size:105%; color:red ;font-weight:normal; line-height:100%!
important; padding:0;margin-bottom: .8 em}
h7{font-size:90%; color:red ;font-weight:normal; line-height:100%!
important; padding:0;margin-bottom: .6 em}
h8{font-size:80%; color:red ;font-weight:normal; line-height:100%!
important; padding:0;margin-bottom: .4 em}
h9{font-size:70%; color:red ;font-weight:normal; line-height:100%!
important; padding:0;margin-bottom: .2 em}


/* ############ ToC ############## */
.page-toc { }
.page-toc-level1 { margin-left: -20mm;font-size:160%;margin-top: .5
em; }
.page-toc-level2 { margin-left: -15mm;font-size:140%; margin-top: .3
em }
.page-toc-level3 { margin-left: -10mm;font-size:120%; margin-top: .1
em }
.page-toc-level4 { margin-left: -5mm;font-size:100%;}

Helge Joao

unread,
Sep 5, 2008, 8:27:38 AM9/5/08
to wikidpad-devel
To have nice big font size red major headings I use WikiPad's Internet
Explorer preview option (Mozilla crashes) with the following
em; } /* list-style:disc; funktioniert leider nicht */

Helge Joao

unread,
Sep 5, 2008, 9:10:44 AM9/5/08
to wikidpad-devel
If you used the Python-script to convert to the reversed heading
syntax, you probably want to use
http://wikidpad.python-hosting.com/wiki/ChangeHeadingLevel
to lower the number of pluses as far es possible on many pages.
Everything is okay without it, but everything looks nicer with fewer
pluses. :)
Reply all
Reply to author
Forward
0 new messages