verbatim code in ZWikiPage
I would like to include some verbatim code in my zwiki. I have used the :: syntax to indicate verbatim example code, as in You will need some variant of the following in .emacs:: ;;the following is wherever you put emacs-wiki.el (setq load-path (cons (expand-file-name "~/emacs/wiki") load-path)) ;;these vars must be defined before the emacs-wiki code is loaded (defvar emacs-wiki-extended-link-regexp "\\[\\[\\([^] \t\n]+\\)\\]\\(\\[\\([^]\n]+\\)\\]\\)?\\]" "Regexp used to match [[extended][links]].") The verbatim tag is being recognized (ie the newlines are honored and the typewriter like font is used, but a lot of the syntax is lost. For example, the above is rendered: ;;the following is wherever you put emacs-wiki.el (setq load-path (cons (expand-file-name "~/emacs/wiki") load-path)) ;;these vars must be defined before the emacs-wiki code is loaded (defvar emacs-wiki-extended-link-regexp "\\\\[\\([^? \t\n]+\\)\\]\\(\\\\([^?\n]+\\)\\]\\)?\\]" "Regexp used to match [extended?links?].") Is this a correctable(ed) problem with zwiki mode? Or am I doing something wrong? Thanks, John Hunter
"John" == John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
John> I would like to include some verbatim code in my zwiki. I John> have used the :: syntax to indicate verbatim example code, John> as in Still haven't solved the problem, but perhaps I've narrowed it a bit. It appears that the WikiNames are still recognized and converted to links in code. I suspect this is a feature, and not a bug. But if your code has '[' or ']' in certain contexts (like the code in the OP), all hell will break loose. I am using ZWiki 0.8.1. In ZWikiPage.py, the function ZWikiPage._wikilink_replace does, among many other things, # strip any enclosing []'s that were used if re.match(bracketedexpr,m): m = re.sub(bracketedexpr, r'\1', m) I suspect this is related to my problem. I have tried to find the part of ZWikiPage that recognizes the 'code' environment, but cannot. For example, if I search for '::' or 'example' in ZWikiPage.py, I find nothing. Can someone point me to the part of the source that recognizes code environments in ZWiki? It seems you could fix this problem with a 'replace wiki link unless in code' construct. Ideally, one should be able at the least to disable the WikiLink conversions in code mode. The wiki poster should be able to input code verbatim, and the reader should be able to highlight it in the rendered html and paste it into their source document. Since almost all programming languages use square brackets in them, it would be nice to preserve them in code environments. Thanks, John Hunter
John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
Still haven't solved the problem, but perhaps I've narrowed it a bit. It appears that the WikiNames are still recognized and converted to links in code. I suspect this is a feature, and not a bug. But if your code has '[' or ']' in certain contexts (like the code in the OP), all hell will break loose.
Hi John, that's right. I think WikiForNow solves this specific problem, and it's one of the changes I hope to get into zwiki 1.0. If you're in a hurry you might want to check what Ken did (and send me a patch if it's easy :). Or, you could: - put ! at the beginning of the line(s) - change your page type to classic wiki or plain text - hack the code to disable the bracketed links if you don't need them -Simon
"Simon" == Simon Michael <simon@joyful.com> writes:
Simon> that's right. I think WikiForNow solves this specific Simon> problem, and it's one of the changes I hope to get into Simon> zwiki 1.0. If you're in a hurry you might want to check Simon> what Ken did (and send me a patch if it's easy :). Since you call the HTML/Structured text conversion before doing the wiki link expansion, it seems that the solution is to write a simple html parser which calls the wiki link regular expression substitutions unless you are in a PRE environment. I am working on that and will let you know if I come up with anything. I'll also try and take a look at Ken's code. Thanks, John Hunter
"Simon" == Simon Michael <simon@joyful.com> writes:
Simon> that's right. I think WikiForNow solves this specific Simon> problem, and it's one of the changes I hope to get into Simon> zwiki 1.0. If you're in a hurry you might want to check Simon> what Ken did (and send me a patch if it's easy :). Ok, got it. I added a function to ZWikiPage.py that calls the wikilink substitutions *unless* you are in a PRE environment. Thanks to Greg Jorgensen <greg@pdxperts.com> on c.l.python who suggested the method used below. Below is the diff on ZWikiPage.py from v0.8.1. I haven't submitted a diff before (I just ran 'diff orig new') so if there is a more appropriate syntax, please let me know. Form all of my tests, it works as desired. A word of warning though, I believe the re objects use some methods not available in earlier releases of python. I have only tested this on Zope-2.3.2 with Python-2.1. 228a229,242
#this function replaces wikilinks unless in an html 'pre' environment def _sub_wikilinks_unless_code(self, s): rgx = re.compile(r'(<pre>.*?</pre>)', re.DOTALL+re.IGNORECASE) chunks = rgx.split(s) out = "" for chunk in chunks: if chunk[0:5].lower() != '<pre>': # Not in a code environment; do wikilinks chunk = re.sub(interwikilink, self._interwikilink_replace, chunk) chunk = re.sub(wikilink, self._wikilink_replace, chunk) out = out + chunk
return out
241,242c255 < t = re.sub(interwikilink, self._interwikilink_replace, t) < t = re.sub(wikilink, self._wikilink_replace, t) ---
t = self._sub_wikilinks_unless_code(t)
252,253c265 < t = re.sub(interwikilink, self._interwikilink_replace, t) < t = re.sub(wikilink, self._wikilink_replace, t) ---
t = self._sub_wikilinks_unless_code(t)
264,265c276 < t = re.sub(interwikilink, self._interwikilink_replace, t) < t = re.sub(wikilink, self._wikilink_replace, t) ---
t = self._sub_wikilinks_unless_code(t)
Happy wikiing, John Hunter
Thanks John! This goes near the top of the todo list. -Simon
participants (2)
-
John Hunter -
Simon Michael