Add custom language code blocks to identify more freely without errors

After ‘’’ add the freer text description that is allowed, sometimes I want to add the note directly after ‘’’ , thus eliminating the need to add a text description under the code block

Any reply would be greatly appreciated

Suppose I customize a programming language whose name is the utf8 character

Here I want to show just one block of code and identify it as common to python and julia

I admit I don’t understand your question.

There are two ways to use back-tick character ` (which is not the same as apostrophe or prime-mark; your post seemed to confuses these somewhat) to trigger code-specific css classes, and also avoid wikifying whatever appears there.

  • Use just one back-tick ` on each end of an inline span, to make it render in code formatting.

  • Use three back-ticks on a line, by themselves, ``` before and after one or more lines, to put those lines into code format as a block.

Somehow you seem to be mixing those two practices.

I notice you have some odd-looking results in your examples, because you type three back-ticks AND put something immediately after them (if something is included in the same line with 3 backticks, then you’re just toggling code on and off and on again, so you see one back-tick that seems to be starting the content of the code span).

Anyway, I see you have some question about how to decide whether you want an inline span of code like this or

a block bit of code like this

Can you say more about why this is a problem/question?

1 Like

The code-block syntax is

  1. Three backticks at the start of the line - or
  2. Three backticks at the stat of the line with a “language” marker-without-spaces

add 1)
standard code block

```
some code
```

add 2)
code block with “language” info

```javascript
if (a > 10) {
// do something. 
}
```

This info is ignored by the TW default parser, but it can be used if code highlighters are installed. Typically the code highlighter plugin uses its own parser to interpret the language marker.

This is not a comment area. As soon as there is a space, the tripple backticks are interpreted as “double backtics” followed by a “single backtick” eg: ```text with spaces becomes `text with spaces`

If you want to add comments, you should add them in the language specific format. So if you copy/paste the code-snippet into real code it should still be interpreted as comment by the native code parser.

So in my example above I used // do something, which is a javascript comment

Also see the TW docs about codeblocks

Hope that helps
-mario

2 Likes

I want to enter a comment after three back quotes, like this

Some possible solutions

But if I type in English and Chinese here, it will parse wrong

This seems to make it possible to insert loose hidden code remarks without error

Three back quotes can be directly added after the content
image

html entities that add Chinese characters do not allow this either

That will not happen. As the syntax is parsed at the moment, there is a very specific usecase. It is not intended to be used for comments. It is a “programming language” placeholder, that will allow 3rd party parsers to evaluate this element.

The default TW parser parses the info, but ignores it. So “misusing” it as a comment field will cause problems.

If you need invisible TW comments you can use them outside the code-block using <!-- wikitext comment --> or inside the code block use the programming language specific comment syntax.

-m

1 Like

[quote=“pmario, post:3, topic:9627”]
code block with “language” info

For what it’s worth, this shortcut for the language parameter is not detailed at https://tiddlywiki.com/#Code%20Blocks%20in%20WikiText

It is a neat solution — parallel to the way a css class can be bundled at end of the opening <<< line before a quoted block — but it’s not fully documented.

So, wherever it is that @XYZ stumbled into the misunderstanding (that this opening was appropriate for “comments”) would have been some other wiki where this code-language syntax was in use, but not explained.

It would be great to have some kind of flag here for easy things to tweak in documentation…

3 Likes

Hear, hear!

I have no idea what such features Discourse offers, but it would be nice to be able to set such a flag, or for any user to respond closing it with a link to the contribution that fixes it.

A whole range of tiddlywiki special characters permit .classname to follow it. eg;

<style>
.u { text-decoration-line: underline; }
</style>

;.u This is bold and underline

It also works on * # ! etc…

2 Likes

The TW prerelease contains the highlight-plugin, which does explain the usage of the code-block language info in the “usage tab”

https://tiddlywiki.com/prerelease/#%24%3A%2Fplugins%2Ftiddlywiki%2Fhighlight

2 Likes

Right.

IMO the Highlights plugin is lightweight. Works. Is extensible. And it’s scripting is not that difficult.

If I had more time I’d try write a Highlights script.
Not for code.
But for cinema screenplays.

This post is not off-topic, I think? In that Highlights and TW go together really well?

A comment, TT

2 Likes

Why must such solutions as the highlight plugin always omit tiddlywiki syntax?

  • Surely adding another brush is what highlight enables and could be added to the plugin if not the project?
2 Likes

That’s a fascinating idea! I’ve only ever seen it used for code or code-adjacent syntaxes. But you’re right. It should be something that you can do for any fairly structured text. Hmmm, the possibilities…

2 Likes

Did you not look at doing this with @pmario’s custom markup some time ago?

I know nothing of that history, but a highlighting implementation has a significant advantage over a custom markup version: you don’t have to change a thing in your text to get a nice display. Simply apply the highlighter to it.

There is also a significant advantage to markup, of course. You can also style the document using your markup hooks, but you can also extract, query, and shuffle it. This is much more powerful.

But if all you want to do is to style it, a highlighter could be very nice.

2 Likes