[Solved] Getting a vertical pipe in a code block

Discussions about the wiki documentation of FreeCAD and its translation.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
chennes
Veteran
Posts: 3908
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

[Solved] Getting a vertical pipe in a code block

Post by chennes »

I'm trying to document a new feature and to do so I need to display a vertical pipe ("|") inside a block of code, like this:

Code: Select all

{{Code|code=
obj=FreeCAD.ActiveDocument.addObject("App::FeaturePython","InternalObjectName")
obj.Label = "User-friendly label"
obj.addProperty('App::PropertyEnumeration', 'ThePropertyName', 'Subsection', 'Description for tooltip')
obj.ThePropertyName = ["Group 1 | Item A", "Group 1 | Item B", "Group 2 | Another item", "Group 2 | Last item"]  // set allowed items
obj.ThePropertyName = "Group 1 | Item A"                  // choose single item
}}
That code doesn't work, the pipe gets interpreted by MediaWiki, and I can't figure out how to stop it. How do I get a | in a code block?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Getting a vertical pipe in a code block

Post by openBrain »

Does '{{|}}' or '|' work?
User avatar
chennes
Veteran
Posts: 3908
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Getting a vertical pipe in a code block

Post by chennes »

Nope -- they both show up literally.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Roy_043
Veteran
Posts: 8550
Joined: Thu Dec 27, 2018 12:28 pm

Re: Getting a vertical pipe in a code block

Post by Roy_043 »

There are two options:

A
Enclose the piping character in nowiki tags:
<nowiki>|</nowiki>

B
Use <syntaxhighlight> tags instead of the {{Code}} template. See https://wiki.freecadweb.org/Help:Editing.

You can also use <pre> tags, but that would mean no syntax highlighting.

BTW
Since PEP8 seems to be quite important in the case of PRs, it would be a good idea if any code samples that are added to the Wiki are also PEP8 compliant. :twisted:
User avatar
Roy_043
Veteran
Posts: 8550
Joined: Thu Dec 27, 2018 12:28 pm

Re: Getting a vertical pipe in a code block

Post by Roy_043 »

Is // a valid way to start a Python comment?
User avatar
chennes
Veteran
Posts: 3908
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Getting a vertical pipe in a code block

Post by chennes »

lol, no, I was just going to write about that -- I fixed it in the code I was editing, but this is copy-and-paste-ware, so it's elsewhere on the page, too.

https://wiki.freecadweb.org/FeaturePyth ... Properties
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply