Is there a way to have not formatted text block in Asciidoc? - asciidoc

Does it exist in Asciidoc (rendered by Asciidoctor) a way to have a block of text where asciidoc formatting is not applied, but it keeps the asciidoc paragraph format (background color, font, font color, etc...) and not preformated format ?
My specific problem
I have a paragraph that I want to render "as I type it"
Array(Element1, Element2, Element3)
Currently, it renders as follow:
And I want to render it as follow:
What I've tried so far
I tried to use code block or literal block, but text appears as preformated, which I don't want:
----
Array(
Element1,
Element2,
Element3
)
----
Or
[literal]
....
Array(
Element1,
Element2,
Element3
)
....
Gives me the following output:

I managed to get what I want by using [%hardbreaks] option to keeping line breaks and by using {nbsp} built-in attribute for non-breaking spaces.
Here is the complete code:
[%hardbreaks]
Array(
{nbsp}{nbsp}Element1,
{nbsp}{nbsp}Element2,
{nbsp}{nbsp}Element3
)

Related

How Can I Create My Own Markup (Like HTML, Markdown, etc.) Language?

I would like to make my own markup language. How can I do that?
For example, I have a file named 'example.timl'.
Inside the file:
$h1$ Heading $\h1$
- This is my own markup language.
I can define my syntaxes here.
$o_list$
One
Two
Three
Four
Five
$\o_list$
$u_list$
One
Two
Three
Four
Five
$\u_list$
$math$
#inf# + 1 = #inf#
$\math$
\\an_input\\: $input type: 'text'$
\\an_input\\
$code lang: 'py'$
print('Would like to have Python syntax highlighting here.')
$code$
$script$
/* I want to have JS scripts just like HTML */
$\script$
And the rendered output can be as I wished.

Change codemirror render function in show-hint.js

I would like to modify rendering hints in code mirror using
render: fn(Element, self, data) in show-hint.js with some id and replace those IDs in hint text inserted while reading value from codemirror using getValue()
Sample hint:
displayText : test
text: %%test%%
And the text should be mapped with some id in the background, it should be retrieved while getting value from the codemirror when the text in the codemirror contains special character '%%'
Could anyone please, help me to achieve this.

add metadata field via pandoc lua filter

I'm processing a markdown document such as
---
title: "dummy title"
highlight: "c"
highlighted: 'highlighted'
---
body text
into a highly-customised latex template where, among other things "c" is being highlighted as part of a larger tex macro. One last step is resisting me: the dummy metadata "highlighted" should not have to be specified here, but I can't find a way to generate it in the lua filter below:
text = require 'text'
newstring = '\\textit{a,b,c,d}'
function meta_vars (m)
-- m.highlighted = 'highlighted' -- not working
highlight = m.highlight
return m
end
function replace (elem)
if elem.text == 'highlighted' then
newstring = newstring:gsub(pandoc.utils.stringify(highlight),
'{\\bfseries '..pandoc.utils.stringify(highlight)..'}')
return pandoc.RawInline("latex", newstring)
else
return elem
end
end
return {{Meta = meta_vars}, {Str = replace}}
with the following custom template
\documentclass[12pt]{article}
\begin{document}
\title{$title$ -- $highlighted$}
\maketitle
$body$
\end{document}
The command to run this example is
pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template _tpl.tex --lua-filter=filter.lua
producing, as advertised
enter image description here
How can I get rid off the dummy highlighted tag in my YAML header?
I don't really understand exactly what you're doing with the latex macros here, but the crux of your question seems to be about adding a new metadata element. The line that you have commented out with --not working seems to work fine for me. You might want to explicitly set the type with
m.highlighted=pandoc.MetaString('highlighted')
but I don't think that will change anything.
I also note that as it is written the newstring variable will be modified whenever the word highlighted appears in the text. With two lines of highlighted the newstring will equal \textit{a,b,{\bfseries {\bfseries c}},d}.
Perhaps you could restate your question with the latex macro stuff removed and just focus on what you want the filter to do.

How do I stop CKEditor from inserting close tags after empty (self-close) MathML tags?

Proper MathML notation of repeating decimals calls for an empty <mline /> tag:
<math><mover align="right"><mn>0.16</mn><mline spacing="6" /></mover></math>
CKEditor doesn't recognize this as a proper empty tag and unhelpfully inserts a closing tag </mline> and messes up MathJax interpretation:
<math><mover align="right"><mn>0.16</mn><mline spacing="3"></mline></mover></math>
This has implications for use of MathML's other empty tags, like <maligngroup/> and <malignmark/>.
Solution was to add mline to CKEditors list of $empty tags in ckeditor_config.js:
CKEDITOR.dtd.$empty['mline'] = 1;
Ended up adding a few more just in case:
_(['mline', 'mspace', 'maligngroup', 'malignmark', 'msline']).each(function(tag, index){
CKEDITOR.dtd.$empty[tag] = 1;
})

Best way to find nested opening and closing tags

I am making a basic discussion board using ROR. When a user posts a response to a message, the input textarea is prepopulated with the message in quotes using a tag: [QUOTE]. As such the format is:
[QUOTE]quoted message goes here[/QUOTE]
Currently, I have a simple solution that replaces [QUOTE] and [/QUOTE] with HTML using message.sub('[QUOTE]', 'html goes here') as long as [QUOTE] or [/QUOTE] still exist. When I go to respond to a quoted message, I convert the HTML back into the [QUOTE] tag to ensure that the prepopulated input textarea doesn't have HTML in it. As such, a quote of a quote, will look like:
[QUOTE][QUOTE]quoted message here[/QUOTE][/QUOTE]
Here is the problem. If I run my current method again, I will get duplicated HTML fields like:
<div class='test'><div class='test'>quoted message goes here</div></div>
Instead, I want to be able to have a solution that looks like:
<div class='test1'><div class='test2'>quoted message goes here</div></div>
And so on...
Any suggestions on the best way to loop this?
If you want to do depth tracking you'll have to use the block method for gsub:
text = "[QUOTE][QUOTE]quoted message here[/QUOTE][/QUOTE]"
quote_level = 0
new_text = text.gsub(/\[\/?QUOTE\]/) do |m|
case (m)
when '[QUOTE]'
quote_level += 1
"<div class='test#{quote_level}'>"
when '[/QUOTE]'
quote_level -= 1
"</div>"
end
end
puts new_text.inspect
# => "<div class='test1'><div class='test2'>quoted message here</div></div>"
You could make this more robust when handling invalid nesting pairs, but for well-formatted tags this should work.
Here's an idea:
Take this regex
(\[QUOTE\])(.*?)(\[\/QUOTE\])
And apply it to your string. It'll match opening tag, closing tag and content. Then take the content and apply regex again. If there are any matches, that'll be your second level of nesting. Repeat while have matches.
Demo here: http://rubular.com/r/MkGsnUj3vL

Resources