Have some AsciiDoc that has a block like...
----
this is a test
with *some* formatted/tabbed text in it
blah
----
...and I would like the text to display like...
this is a test
with some formatted/tabbed text in it
blah
...where the word "some" is bold.
In AsciiDoc, the double ---- lines signify ListingBlocks, which only preserve certain formatting aspects of your text (line and whitespace formatting), according to the AsciiDoc documentation on Delimited Blocks ( with the exception of using [subs="quotes"], as you noted in your answer).
Other ways to include bold formatting in a delimited block include the "Admonition Block", ExampleBlock, OpenBlock, QuoteBlock, and SidebarBlock options.
Example Blocks:
**Admonition Block:**
[NOTE]
====
here *is* my text
====
**Example Block:**
====
here *is* my text
====
**Open Block:**
--
here *is* my text
--
**Quote Block:**
[quote, quote author]
____
here *is* my text
____
**Sidebar Block:**
****
here *is* my text
****
Example Blocks Output:
Here is what I came up with. This post was helpful...
http://www.methods.co.nz/asciidoc/faq.html#_how_can_i_format_text_inside_a_listing_block
[subs="quotes"]
----
this is a test
with *some* formatted/tabbed text in it
blah
----
This allowed me to retain the formatting/whitespace in the text in addition to adding the formatting (bold in this case) to the text.
As far as I know, this is only possible with docbook code, you can see an example here:
++++
<screen>hostname $ <userinput>date</userinput>
Sun Apr 1 12:34:56 GMT 1984</screen>
++++
Of course, it will only work if your engine was configured with the correcting style for screen and userinput.
Related
I'm writing some coding tutorials in rST/Sphinx and I'd like to differentiate the input (ie: the code-block) from the output (to the terminal). Because the output needs to be literal too, I can't simply use a custom class or container, as these still get interpreted and don't display correctly (see below). How can I create a class or container or something which I can apply to a subset of literal blocks?
Note that this doesn't need to be anything fancy - maybe just changing the background colour on my "output" blocks compared to my "code-block" blocks.
I've tried:
Creating a custom class called "terminal", but this is still interpreted and returns errors about its contents:
.. container:: terminal
-----------------------------------------------
MY **EXAMPLE** GOES HERE
-----------------------------------------------
... produces an interpreted output, the class is applied correctly, but the horizontal lines are missing, the "EXAMPLE" is bold etc.
Nesting a literal block inside the terminal container:
::
.. container:: terminal
-----------------------------------------------
MY **EXAMPLE** GOES HERE
-----------------------------------------------
... produces the literal output formatted as input code:
.. container:: terminal
-----------------------------------------------
MY **EXAMPLE** GOES HERE
-----------------------------------------------
Nesting the other way around:
.. container:: terminal
::
-----------------------------------------------
MY **EXAMPLE** GOES HERE
-----------------------------------------------
... produces a div with the terminal formatting around a nested div with the literal block, which retains the standard literal formatting (which I want to over-ride).
I think there must be something really simple I'm missing but I really can't see it!
Try .. code-block:: bash where "bash" is the name of the language to which you want syntax highlighting applied. Available syntaxes are provided by Pygments as "lexers".
.. code-block:: bash
-----------------------------------------------
MY **EXAMPLE** GOES HERE
-----------------------------------------------
If you are dissatisfied with the syntax highlighting provided by your Sphinx theme, you can override it with a custom style.
As an example of what is possible, I changed the style for a specific selector. Put something similar in your theme's CSS.
div.highlight-text > table > tbody > tr > td.code > div > pre {
background-color: #32cd32;
}
I'd like to know how to compile multiple pandoc files into one output document, where each input file has a title block.
E.g. suppose I have two files:
ch1.md:
% Chapter 1
% John Doe
% 1 Jan 2014
Here is chapter 1.
ch2.md:
% Chapter 2
% Jane Smith
% 3 Jan 2014
Here is chapter 2.
Typically with multiple input files you can compile them by providing them to pandoc:
pandoc ch1.md ch2.md --standalone -o output.html
However pandoc concatenates the input files before compiling, meaning only the first title block (from ch1.md) is styled appropriately.
I would like each title block to be styled appropriately (e.g. in html, the first line of the title block is styled with <h1 class="title">, the second <h2 class="author"> and so on).
(Note: I have also tried compiling each chapter as standalone separately, then concatenating these together using pandoc. This removes the title styling for chapters after 1, though keeps styling for the authors/date).
Why? I can:
compile each chapter in its own separate document and the author/title/date is marked up appropriately
compile the entire document together and author/title/date is marked up appropriately for each chapter (can use the --chapters option)
I could just specify the heading with '#' (h1), author with '##' (h2), and date with '###' (h3) in each chapter file directly but this means pandoc doesn't "know" what the title/heading/date of my document are, so (e.g.) if I compile to latex it won't use the \date{} or \author{} tags appropriately.
I wrote a pandoc filter that when run on each individual chapter's file, inserts the title block as headings (level 1 for title, level 2 for author, level 3 for date. This is what the HTML writer does).
This lets you run pandoc on each chapter individually (to produce the pandoc'd output plus the formatted title block), and then run pandoc on all the chapters together to compile the single document.
The filter is here on gist (I take no responsibility for malfunctioning code, etc): https://gist.github.com/mathematicalcoffee/e4f25350449e6004014f
You could modify it if you wanted it to format differently (for example like this the author/date appear in the table of contents since they are headings, which is not quite right... but that's a different problem as it happens with the default HTML writer too).
My workflow is now something like this:
FORMAT=latex # as understood by -t <format> in pandoc
FLAGS=--toc # other flags for pandoc, --smart, etc
OUT=pdf # output extension
for f in Chapter*.md; do \
pandoc $FLAGS -t $FORMAT --filter ./chapter.hs $f; \
echo ""; \
done | pandoc $FLAGS --standalone -o thesis.$OUT
where I've chmod +x chapter.hs and it's in the current directory.
(I additionally have a title.txt that I stick out the front with the entire thesis' title block (as opposed to each chapter's title block)).
I received some help from the pandoc google group which was great.
You can't do this with the % title blocks, but you can do it with the new YAML title blocks.
Start each document like this:
---
title: Chapter One
author: Me
date: June 4
...
When the documents are concatenated together, the first value set will take precedence over the others, so the subsequent YAML lines using the same parameter (e.g. "title:") will be ignored. (See the readme under "Extension: yaml_metadata_block".)
How to remove a YAML header like this one from a text file in Ruby:
---
date: 2013-02-02 11:22:33
title: "Some Title"
Foo: Bar
...
---
(The YAML is surrounded by three dashes (-))
I tried
text.gsub(/---(.*)---/, '') # text is the variable which contains the full text of the file
but it didn't work.
The solution mentioned above will match from the first occurrence of --- to the last occurrence of --- and everything in between. That means if --- appears later on in your file you'll strip out not only the header, but some of the rest of the content.
This regex will only remove the yaml header:
/\A---(.|\n)*?---/
The \A ensures that it starts matching against the very first instance of --- and the ? makes the * be non-greedy, which makes it stop matching at the second instance of ---.
Found a solution, regex should be:
/---(.|\n)*---/
I need to highlight comments on mcedit using syntax file.
One line comment begins with "--" and may end with "\n" or with "--".
My syntax file content which responsible for comments is following:
context -- \n brown
spellcheck
context /\* \*/ brown
spellcheck
Example of one line comments is here:
-- This line starts with comment
this is code -- This is another comment, which ends with '\n'
this is another code -- This is another comment, which ends with '--' -- this is another code after comment
How to highlight one line comment that may end with "\n" or with "--"?
This question is probably more suited to superuser, however:
Based on the man page, I would try:
context linestart -- \n brown
spellcheck
context linestart -- -- brown
spellcheck
Does anyone have or know of a Ruby script that converts text to html?
Example:
I have a file that contains the following text:
Host Name
Info1
Line1
Info2
Line2
I want to have ruby convert it to the following html output
Host Name
Info1
Line1
Info2
Line2
I tried running RedCloth but got the following error:
The program can't start because msvcrt-ruby18.dll is missing
Thanks
Thanks
That depends upon what you mean by "text to HTML." There are several "web text generators" that convert easy-to-read free text with minimal markup (asterisks to indicate bold, double-spaced paragraphs get surrounded in <p> tags, etc). The most common, for Ruby, are Redcloth, which implements Textile free text, and Bluecloth, which implements Markdown.