asciidoc macros - asciidoc

I use asciidoc for rendering text.
I have difficulties to understand macros.
My goal is to have a simple macro processing (like in LaTeX).
I would like to write two Macros:
FOO should be replaced by "bar"
MYTEXT(xyz) should be replaced by: "This is my text xyz!"
(perhaps with a different way to pass the parameter 'xyz')
Example file abc.txt:
text text text
FOO text FOO
text text text
MYTEXT(jajaja)
This should result in
text text text
bar text bar
text text text
This is my text jajaja!
I would expect that the definition of FOO and MYTEXT has to go into the file abc.conf; probabely into the secion [macro].
Additional question:
Are there problems with the pattern matching, if
FOO should be replace with 'bar' and FOOX with 'barbar'?

For the task of substituting FOO into bar and FOOX into barbar I would use the substitution syntax:
= AsciiDoc title
:FOO: bar
:FOOX: barbar
Regular text here using substitutions: {FOO} is bar and {FOOX} is barbar.
As you can see, you declare the substitution as :VARIABLE: and you use it as {VARIABLE}.
As to actually creating new macros, macros are usually of the type macroname:content[Text input]. They are documented here for the Python AsciiDoc project and eventually here for the ruby based AsciiDoctor project but I have never really used them, I prefer substitutions and conditional blocks.

There is a separate project, that I am associated with
http://github.com/verhas/jamal
which is a macroprocessor and it is available as an Asciidoctor preprocessor. Note that this is not Asciidoc, which is the format, but the implementation of the converter, Asciidoctor.
I think that Jamal just does exactly what you are looking for. It has complex macro processing capabilities that superseed those of Asciidoc and there are also a lot of built-in macros, some replacing, some extending the Asciidoc formatting and macro capabilities.

Related

How can I get %i Ruby arrays to be properly highlighted in Vim?

My Vim is not highlighting the relatively new %i syntax. Here's an example:
I included a %w example, which works properly, to show the desired effect.
How can I get Vim to highlight %i properly?
If you’d type :syn ⏎ in control mode while editing any ruby file, you’ll see all the syntax definitions (or open system-wide syntax theme for ruby /usr/share/vim/vim81/syntax/ruby.vim or where is it located.)
The one responsible for %i[] would be rubySymbol.
%i[] is by no mean “relatively new,” the issue is your color theme does not highlight symbols differently. Not only literals, all the symbols. Run:
:hi rubySymbol term=bold ctermfg=Red
and you’ll see it perfectly works. You might tune it according to your needs (see e. g. rubyString for the inspiration) and put this somewhere in your ~/.vim/syntax/ruby.vim.
By default, Vim highlights Ruby's string delimiters and symbol delimiters differently. The string delimiters are highlighted as type Delimiter, and the symbol delimiters are highlighted the same as symbols, which is, by default, of type Constant.
If you want to highlight the %i and brackets the same as the %w, you can run the following command:
:hi link rubySymbolDelimiter rubyStringDelimiter
If you like that setting, you can put it in a file called .vim/after/syntax/ruby.vim and it will be picked up automatically whenever the Ruby syntax is enabled.
Note that in newer versions of Vim, the above command will also cause the colon in front of a symbol to be highlighted the same way as the %i. That functionality isn't configurable, since they both use the rubySymbolDelimiter match group.

Support "styled text" in a scriptable Mac application (Cocoa Scripting)

My app supports being scripted with Applescript.
I am trying to make styled text content, stored in NSAttributedString objects, available to an Applescript user.
I thought I could simply deliver styled text with the NSAttributedString class, just like I deliver plain text with the NSString class, but that does not work - Cocoa Scripting then reports that it cannot convert or coerce the data.
I wonder if I'm missing something or if this is just plain impossible with the standard classes supported by Cocoa Scripting?
AppleScript does know the "styled text" type, as seen in this example:
set stxt to "foo" as styled text
So, if AppleScript knows this type by default, shouldn't the Cocoa Scripting engine support it as well somehow?
As always there are many choices for solving an AS problem.
In my scriptable text editor (Ted), I implemented the Text Suite, which is based on rich text (NSTextStorage, a subclass of NSMutableAttributedString). I wanted to be able to script tabs in my paragraphs, so I added a style record, which contains all the paragraph style information. This lets me write scripts like this:
tell application "Ted"
set doc1 to make new document at beginning with properties {name:"Document One"}
tell doc1
set p1 to make new paragraph at end with data "Paragraph One" with properties {size:24, color:maraschino}
set p2 to make new paragraph at end with data "Paragraph Two" with properties {style:style of paragraph 1}
set color of paragraph 1 to blue
end tell
set doc2 to make new document at beginning with properties {name:"Document Two"}
copy p1 to beginning of doc2
properties of paragraph 1 of doc2
end tell
Since p1 is rich text, the second document ends up with both the text and formatting of the first paragraph of the first document.
You can also ask for the properties of a piece of text, where I have implemented the usual Text Suite properties, as well as a "style" property for paragraph style (backed by NSParagraphStyle, since I wanted to be able to script the tab stops):
properties of paragraph 1 of doc2
Result:
{height:60.0, italic:false, size:24, style:{paragraph spacing after:0.0, head indent:0.0, line break mode:0, alignment:4, line spacing:0.0, minimum line height:0.0, first line head indent:0.0, paragraph spacing before:0.0, tabs:{"28L", "56L", "84L", "112L", "140L", "168L", "196L", "224L", "252L", "280L", "308L", "336L"}, tail indent:0.0, maximum line height:0.0, line height multiple:0.0, default tab interval:0.0}, color:blue, width:164.109375, font:"Helvetica", bold:false, class:attribute run}
This works well for passing rich text within my application, but may not be as useful for passing styled text to other applications, which may be what you wanted to do. I think adding a "style" property (of type record) is probably the best way to convey style info for use in other scriptable apps. Then in the second app, the scripter can make use of any properties in the style record that the second app understands.
It looks like there is no implicit support for styled text in AppleScript. And there is also no common interchange record type for passing styled text.
AppleScript was developed in the pre-OSX days when styled text was often represented by a combination of a plain text (in System or MacRoman encoding) and a styl resource. With Unicode came an alternative format of a ustl style format. These are still used with the Carbon Pasteboard API (PasteboardCreate etc.) today. Yet, none of these seem to have made it into the use with AppleScript.
The fact that AppleScript knows of a styled text type has no special meaning. Even its class is just text.
Update
I just found that Matt Neuburg's book "AppleScript The Definitive Guide" mentions styled text and gives an example where it's indeed showing a record containing both the plain text (class ktxt) and style data (class ksty) with data of type styl, just as I had expected above. He also points out that most applications don't use that format, though.
So, it appears using a record with style resource data is indeed the intended way, only that hardly anyone knows about it. Go figure.

Does an Indesign syntax highlighter exist?

Does anybody know of a non-manual method of highlighting syntax when pasted in InDesign?
I'm trying to show code of a project in an InDesign documentation but don't want to have to manually highlight the code, and preferably add numbered rows too.
Is there a plugin to achieve this?
This is the style in which I'd like to format the code.
Cheers
Not sure if you worked out an answer to this, but there's no magic button that will solve your problem.
However, InDesign does have a facility in each Paragraph style called GREP that can do what you're looking for.
This lets you write 'regex' or 'regular expressions' that are just rules for what to apply a given character style to. Yes, they look about as meaningful as Harry Potter incantations at first glance, but 2 or 3 simple regexes will get you a long way.
For instance:
(\<|<)!--\s*.*?\s*--(\>|>)
Will target HTML comments only.
(?<=").*?(?=")
This will target anything wrapped in straight double quotes.
(?<=\().*?(?=\))
This will target any text inside parentheses ().
There's an '#' symbol button in that GREP style next to where you type the regex - that gives you a drop-down menu that is almost like a 'Regex Wizard'. Try that too.
When you've got a regex that works, create a new character style for the text color and select it in the 'Apply Style' input.
Regexr.com has a tool that is good for testing this stuff. Paste your code sample in the bottom panel and your line of regex in the top. The bits that it targets will turn blue.
There is a searchable community panel on the left where people have probably already written expressions like the one you need.
I'm working out a JavaScript highlighter at the moment. It's a shame there's no communal 'Indesign style sharing library'.
Best of luck.
If had luck pasting syntax highlighted code into a Rich Text editor like Libre Office and then pasting it into Indesign. Just make sure whatever font your syntax highlighted code is in is also in InDesign because you'll get font missing errors when you pre-flight the book.

Notepad++ Custom Language Highlighting

I have a specific language (its private, and closed source) that I'm writing code highlighting for in Notepad++. I've never done anything like this before... so, for the most part, I'm clueless.
There are a bunch of keywords, and I've figured out how to implement those, but the strings are denoted by square brackets ([ and ]) instead of normal quotes. How do I register those as strings in the XML file?
Another thing, the language relies heavily on recursion and nesting; is there some way to say "Level 1 of the square brackets is this color, level 2 is this color, etc..."?
There's a useful help page that explains how to use the GUI to define a custom language for Notepad++. As Alex K noted in a comment above, the option for setting string delimiters appears to be in the Delimiters boxes in the Operators tab. It doesn't look like it supports different colours for different levels of nesting, though.
Update for those who have been asking the same question:
(Temporary) Documentation for custom syntax highlighting is on: http://udl20.weebly.com/index.html
There is a link to this in Notepad++ but it doesn't stand out.
I had log4net files that I wanted to view in Notepad++. They contained lines like:
2015-06-03 16:38:10,751 [Compname][Thread:29][FATAL]
To highlight [FATAL] just the keyword list wasn't enough. I added this:
On tabpage "Folder & Default" > Folding in code style 1: >
Open: [
Close: ]
On tabpage "Keyword lists" > 1ste group > FATAL with some styling.

is it possible to make the caret jump between highlighted text snippets in Scintilla?

I want to know if it is possible with Scintilla API to make something like the following.
I have the following call:
cook(foo , bar);
where foo and bar are only highlighted and the caret is at the beginning of foo.
now if i type anything, it will override foo, and if I pressed Tab, the caret will jump to the highlighted bar.
FingerText does this with snippets (for Notepad++), but the majority of it uses Scintilla, so I would imagine it should be possible to fairly easily adapt it for another Scintilla based editor.

Resources