Posting VHDL code in blog or forum
Posting plain text in the blog or forum should not be a problem to anybody who can type – no knowledge of programming languages is necessary. If, however, somebody wants to post a snippet of VHDL code, situation changes dramatically…
- First, the poster has to know what format is expected: plain text, rich text, HTML?
- Then the plain VHDL code must be converted to proper format (with exception of expected plain text format).
- Finally, converted VHDL must be pasted in the blog/forum editor.
Here’s how it looks on our website:
For blog posts/comments
We have installed rich text editor plugin, so the situation should be simple:
- For quick post, just copy VHDL code from your favorite editor to the blog editor.
- To make the code snippet look more like in the real code editor, select it and click toolbar button marked “Code snippet” (the button looks like this “#_“).
- If you have time and patience, you may select individual keywords and make them bold (or change their color).
For forum topics and replies
For now, restricted HTML is the only allowed format for majority of members. [See comment #2 for good news!]
- The use of “<code>…</code>” tag pair around the code snippet should help, but there are two more issues:
- Four characters play special role in HTML: ‘<‘, ‘>’, ‘&’ and ‘”‘ (double-quote), so they should be replaced with special entity names: <, >, &, " (semicolon is the part of entity name, comma is not).
- Forum editor parser removes leading spaces and tabulations, so to maintain nice indentation you have to use non-breaking spaces that have the following entity name: .
The first step is easy: I recommend typing <code> in a new line, hitting Enter twice and typing </code> before pasting code snippet in the empty line between two tags.
The second step can be done manually via Search&Replace; be careful with ‘&’ representing concatenation in VHDL – you should replace it with some rare string, deal with other symbols and then replace rare string with &.
If it seams too difficult, try excellent free editor Notepad++ in which TextFX | TextFX Convert | Encode HTML menu option will do all those replacements in the selected text in one step.
The third step can be done in any text editor; first replace all tabulations with proper number of non-breaking spaces (most frequently 4: ) and then replace plain spaces with non-breaking ones.
While good programmer editors may have option to export your code directly to HTML, usually they will not do space/tab replacement.
The rules presented above should work for everybody. If you have better, revolutionary ideas, let us know in the comments to this post.
Leave a Reply
You must be logged in to post a comment.
If you have Notepad++ and cannot see TextFX menu, you probably have to install TextFX Characters plugin using Plugin Manager in Plugins menu…
Good news! Recent update of Rich Text Editor also works in Forums, so the trick with pasting VHDL block and marking it as code snippet should work everywhere now…