I am using sphinxcontrib-httpdomain extension to write Sphinx documentation. This extension is able to generate a 'routing table' page which I defined like this.
I also defined a substitution which I use in my docs:
# conf.py
rst_epilog = """
.. |mongodb_icon| raw:: html
<span class="icon-dbs-mongodb"></span>
"""
However, when I put this substitution in the synopsis directive of HTTPDomain extension, it is rendered out as plain text...
.. http:post:: /companies/
:synopsis: Some text whatever |mongodb_icon|
How can I force this page (routing table) to render out my substitutions properly?
Related
I'm using Pandoc to generate a Reveal.js presentation. It includes code in fenced code blocks, like this:
```java
// Some Java code
```
Reveal.js supports a way to add a highlight to a specific line or range of lines, with the data-line-numbers="1" attribute that should be added to the <code> tag.
I've tried to add this attribute to the fenced code block in various ways, such as this
``` { .java data-line-numbers="1" }
// Some Java code
```
But I can't get it to work. Is there a way to use Reveal.js's data-line-numbers in Pandoc? Or perhaps Pandoc has a way to achieve something similar? Or do I need to give up and just use those messy <pre><code> HTML tags in my Markdown?
The correct syntax should be:
``` {.java .number-lines}
// Some Java code
```
Pandoc does the syntax-highlighting itself, and is sensitive to the number-lines class.
Pandoc's HTML output for code blocks does not follow the way that reveal.js expects them to be written. E.g., the default pandoc way of indicating that lines are to be numbered is to mark the block with the number-lines class, while reveal.js expects a boolean data-line-numbers attribute. Even adding the data-line-numbers attribute manually won't work: pandoc wraps the code in <pre> and <code> elements and adds all code block attributes to the <code> element, while reveal.js looks for them in the <pre> element.
I struggled with pandoc's way of handling code blocks for reveal.js output myself, so I wrote this lua-filter: revealjs-codeblock. This filter adjusts pandoc's HTML output such that it follows the reveal.js specs.
It supports the .number-lines and .numberLines classes as well as the data-line-numbers attribute.
I just need to embed a small piece of html or xml in the reStructuredText (sphinx) so that the browser can render them in the generated HTML files, like the following little piece
.. raw:: html
testurl
or
.. raw:: html
<math><apply><plus/><ci>a</ci><apply><minus/><ci>b</ci><ci>c</ci></apply></apply></math>
No matter I tried directives like "literal", "raw", "container", "code", either the html code is displayed as the inner text of some "p" block (so the browser display the code rather than render it), or the code just disappear from the output.
What is the correct way to embed html or xml in the reStructuredText (sphinx) so the browser can render them? I just want to html or xml just be placed there intact.
You need to add a blank line between the raw directive and your code.
.. raw:: html
testurl
I would suggest indenting 4 spaces to be consistent with Python formatting, but 2 is fine.
On the main page of every repository in GitHub or BitBucket it shows the Readme.md in a very pretty format.
Is there a way to make the same thing with ruby? I have already found some gems like Redcarpet, but it never looks pretty. I've followed this instructions for Redcarpet.
Edit:
After I tried Github's markup ruby gem, the same thing is happening.
What is shown is this:
And what I want is this:
And I'm sure it's not only css missing, because after 3 backquotes (```) I write the syntax like json or bash and in the first image it is written.
Edit2:
This code here:
renderer = Redcarpet::Render::HTML.new(prettify: true)
markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)
html = markdown.render(source_text)
'<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>'+html
Generated this:
Github provides its own ruby gem to do so: https://github.com/github/markup.
You just need to install the right dependencies and you're good to go.
You need to enable a few nonstandard features.
Fenced code blocks
Fenced code blocks are nonstandard and are not enabled by default on most Markdown parsers (some older ones don't support them at all). According to Redcarpet's docs, you want to enable the fenced_code_blocks extension:
:fenced_code_blocks: parse fenced code blocks, PHP-Markdown style. Blocks delimited with 3 or more ~ or backticks will be considered as code, without the need to be indented. An optional language name may be added at the end of the opening fence for the code block.
Syntax Highlighting
Most Markdown parsers to not do syntax highlighting of code blocks. And those that do always do it as an option. Even then, you will still need to provide your own CSS styles to have the code blocks styled properly. As it turns out, Redcarpet does include support for a prettify option to the HTML renderer:
:prettify: add prettyprint classes to <code> tags for google-code-prettify.
You will need to get the Javascript and CSS from the google-code-prettify project to include in your pages.
Solution
In the end you'll need something like this:
renderer = Redcarpet::Render::HTML.new(prettify: true)
markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)
html = markdown.render(source_text)
As #yoones said Github shares their way to do it but to be more precise they use the gem "commonmarker" for markdown. Though as far as I can tell this thing does not give the full formatted HTML file but only a piece that you insert into <body>. So you can do it like I did:
require "commonmarker"
puts <<~HEREDOC
<!DOCTYPE html>
<html>
<head>
<style>#{File.read "markdown.css"}</style>
</head>
<body class="markdown-body Box-body">
#{CommonMarker.render_html ARGF.read, %i{ DEFAULT UNSAFE }, %i{ table }}
</body>
</html>
HEREDOC
Where did I get the markdown.css? I just stole the CSS files from an arbitrary Github page with README rendered and applied UNCSS to it -- resulted in a 26kb file, you can find it in the same repo I just linked.
Why the table and UNSAFE? I need this to render an index.html for Github Pages because their markdown renderer can't newlines within table cells, etc. so instead of asking it to render my README.md I make the index.html myself.
How do I render a strikethrough (or line-through) in an adoc file?
Let's presume I want to write "That technology is -c-r-a-p- not perfect."
That technology is [line-through]#crap# not perfect.
As per Ascii Doc manual, [line-through] is deprecated. You can test here.
Comment from Dan Allen
It's important to understand that line-through is just a CSS role. Therefore, it needs support from the stylesheet in order to appear as though it is working.
If I run the following through Asciidoctor (or Asciidoctor.js):
[.line-through]#strike#
I get:
<span class="line-through">strike</span>
The default stylesheet has a rule for this:
.line-through{text-decoration:line-through}
You would need to do the same.
It is possible to customize the HTML that is generated using custom templates (Asciidoctor.js supports Jade templates). In that case, you'd override the template for inline_quoted, check for the line-through role and produce either an <s> or, preferably, a <del> instead of the span.
If you're only targeting the HTML backend, you can insert HTML code verbatim via a passthrough context. This can be done inline by wrapping the parts in +++:
That technology is +++<del>+++crap+++</del>+++ not perfect.
This won't help you for PDF, DocBook XML, or other output formats, though.
If the output is intended for HTML you can pass HTML.
The <s> HTML element renders text with a strikethrough, or a line
through it. Use the element to represent things that are no longer
relevant or no longer accurate.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/s
To render as:
Example text.
use:
1. Pass inline:
Example +++<s>text</s>+++.
2. Pass-through macro:
Example pass:[<s>text</s>].
3. Pass block:
++++
Example <s>text</s>.
++++
Markdown already ignores everything within a <div> element, and various other block-level elements. However, I need to tell Markdown to ignore everything within <code> blocks as well. Is there a way to tell Markdown to do this?
As an FYI, I am using BlueCloth.
The Markdown spec does not specify how <code> blocks should be processed. What exact type of markup are you trying to get the Markdown processors to ignore?
Here is the Markdown Syntax page.
I'm not exactly sure what you want to achieve.
You have something like the following right?
#Heading
<code>
$my = 'php code here';
</code>
Other text
Do you want your output to be like the one below?
<h1>Heading</h1>
<code>
$my = 'php code here';
</code>
<p>Other text</p>
For code in markdown you have to indent the code by four spaces so what you should do is the following in your markdown source file.
#Heading
$my = 'php code here';
Other text
The code is indented four spaces and markdown will surround it with and tags automatically.