Ticket #213 (new task)

Opened 4 years ago

Last modified 7 months ago

Using %% in highlighted code

Reported by: NilsLindenberg Owned by: unassigned
Priority: high Milestone: blue-sky
Component: formatters Version: 1.1.6.0
Severity: major Keywords: highlighter markup
Cc:

Description

copied from SuggestionBox --NilsLindenberg

Since the %% is used as code-markup in wikka and used in languages like batch and mysql as well, users will run into problems trying to highlight mysql-code. There were discussions about a replacement of it:

I want to produce a code sample page in wikka with DOS batch code. The code syntax requires two percent characters together to markup a variable. Example: % %variable% % (without the spaces). Wikka always tries to format the text as code, even if I format the DOS code inside a code block, even if I %% marked it as code with two percent characters like this here%%

Is there a solution? I could not find a literal entity for "percent"

You could use % which is the numerical entity reference for the percent sign: % - but *within* a code block an entity is "escaped" - a problem by itself, and so it wouldn't help. See: %%some text with &#37&#37 embedded in it%%

But it should be possible to just plug in a piece of code without having to worry about which characters and strings to somehow escape - maybe the double percent isn't such a happy choice for Wiki markup of "code"; should we find a character combination that is less likely to be a syntactical meaning in an artificial language? (And how do you markup Wiki markup as **code**?) -- JavaWoman

How about the € (euro) Symbol? Or is it to new? --NilsLindenberg

The main problem with the € (euro) symbol is not that it's new, but that it's hard to type: most keyboards don't have the symbol. And it might occur in code as well (imagine a sample conversion routine). Wiki markup should be easy to type. So we need a symbol (or sumbol combination, maybe), that's:

# easy to type # not likely to occur in any programming code (note "likely" - you can never completely exclude it; think of APL!)

The exclamation mark still seems to be "free", and although a single exclamation mark often is used for negation in programming languages (and in comments, of course) a double one isn't (just don't use rows off exclamation marks in your code comments); or else a combination of an exclamation mark with something else (that is not itself an "operator" in languages). Maybe we should do a search (Google?) to check whether **!!** or a combo is actually an operator in any language. -- JavaWoman


In any wiki displaying code which contains that wiki's markup to indicate a code block will be a problem. While our "code" markup with a double percent is not likely to be a part of the syntax of any popular language other than our own Wikka markup (though it likely is part of the syntax of some language) it could still easily occur in some code comment and thus throw the formatter off.

The only generic solution is to somehow "escape" ""%%"" in a code block so it isn't seen by the formatter as the end of the block. There are two problems with this:

# Users must remember to "escape" the ""%%"" (although not doing that will be easily visible as a problem in rendering code) # Code with "escaped" ""%%"" can no longer be copied from the page source as is, while copying from the rendered code already has the disadvantage of losing some of the formatting (e.g, tabs being replaced by spaces)

Copying of code has been made a lot easier on this site with the "grab code" handler (still a beta feature. If any method of escaping ""%%"" in code is used, and the grab code handler could "unescape" before delivering the code, the second problem would be basically solved (provided we actually distribute the handler with a coming version of Wikka). That leaves us with finding an escape method that's easy for users to implement.

There are two requirements for an "escaped" ""%%"" then: # Easy to remember and apply by end users # Not (not likely) part of the syntax of any language

One option that came up during a #wikka conversation was to just replace ""%%"" in code with a keyword. A good candidate might be **DOUBLE_PERCENT** - it's easy enough to remember and easy to implement: The formatter could detect this very simply and replace it by ""%%"" before feeding the content of a code block to GeSHI for rendering; the grab code handler could just as easily replace it before making the code block available for download.

Thoughts anyone? --JavaWoman

It's a good idea, but: You are sure DOUBLE_PERCENT is no reserved word in a language? Or unlikely to comme up in a code? --NilsLindenberg

Try googling for 'DOUBLE_PERCENT': **this** page comes up on top, with 8 others referring to the name being used (in lowercase) in two programs, as (part of) function names (i.e., not as reserved words). It's certainly not a reserved word in any of the languages GeSHi currently has support for, going by the language files it comes with. There's no way to be 100% certain but it seems to be a pretty safe bet. --JavaWoman

Change History

Changed 4 years ago by NilsLindenberg

MAybe it would be the simplest solution to allow %%% as code-markup as well?

Changed 4 years ago by BrianKoontz

  • milestone set to 1.1.7.2

Assigned to milestone 1.1.7.2.

Changed 3 years ago by JavaWoman

Re-reading this, the simplest solution seems to be to have the formatter "escape" any %% within a code block before sending it to the code formatter, and unescaping the result received back.

That would avoid people having to escape code they want to post (which would be a really bad solution IMO).

Changed 2 years ago by notmeneither

What about using some sort of html-esque code markup? i.e.

<code>

REM Look its a variable in a for loop!

FOR /F "eol=;" %%s in (foo.bar) do something

</code>

Changed 7 months ago by BrianKoontz

  • type changed from defect to task
  • milestone changed from 1.3 to blue-sky
Note: See TracTickets for help on using tickets.