If I write this reStructuredText:
Blah, blah.
Here is my code:
.. parsed-literal::
some code
and then convert it to HTML with rst2html, some code is rendered as less indented than "Here is my code:".
How can I get some code indented by as much as "Here is my code:"? In other words, how can I vertically align some code and "Here is my code:"?
Your example is rendered into this piece of html code:
<p>Blah, blah.</p>
<blockquote>
Here is my code:</blockquote>
<pre class="literal-block">
some code
</pre>
Which doesn't make much sense: line Here is my code: is not a quote here.
So I would rather write it this way:
Blah, blah.
Here is my code:
.. parsed-literal::
some code
which renders to:
<p>Blah, blah.</p>
<p>Here is my code:</p>
<pre class="literal-block">
some code
</pre>
Then to change an alignment of some code block, you would need to tweak css.
Related
The code is listed below, using the bootstrap class class="list-group-item-text".
As the image here shows, the text seems to have a duplicate version just above it - looks almost like dotted lines.
`
<asp:Panel ID="pnlInstructions" runat="server" Visible="true">
<h4>Instructions:</h4>
<div class="form-inline col-lg-12" id="Instructions" style="padding-top:10px;padding-bottom:20px;padding-left:10px;">
<ol class="list-group-item-text" style="text-emphasis:filled;outline:none;">
<li>First, please use MyEd to get your extract file ready.</li>
<li>Then, fill in the following to Log in.</li>
</ol>
</div>
</asp:Panel>
`
I've researched the problem using the word "sprites", but that seems to have a different meaning than I expected, since I thought it meant "unwanted junk" in a display.
I'm not sure if this appears on all browsers.
I noticed that in HTML produced by knitr from my RMarkdown document, sections are marked up thus:
<div id="chunk_id" class="section level2">
<h2>...</h2>
<p>...</p>
</div>
and so on. I think it's best practice to use a <section> element rather than a <div> here (reference 1, reference 2), so I forked the RMarkdown code to see if I could make a change and a PR. In the code I found the following:
#'#param section_divs Wrap sections in <div> tags (or <section> tags in HTML5),
#' and attach identifiers to the enclosing <div> (or <section>) rather than the
#' header itself. ```
so it seems like there is no need for a change to RMarkdown - it will already use <section> in the way I want, if it is told to output HTML5.
My question is: how do you tell knitr to output HTML5? I have
output:
html_document:
section_divs = TRUE
but no idea how to "switch on" HTML5.
I've found a tool I can use to translate text googletrans
this is how it works
from googletrans import Translator
translator = Translator()
result = translator.translate(text, dest=lang)
print(result.text)
but in the case that my text might come from django-ckeditor so it includes html tags for example
<h1>Some Title</h1>
<p>Some Text</p>
I need to pass this text to it and still maintain the html tags, so far it tends to break that symetry and the text formatting gets ruined to mention it fails to translate correctly.
There's tools like beautiful soup that can help you read html text, that direction looks like it's going to be bloated code that "barely" works, I'm curious if someone knows of a way to get it to work more cleanly.
Currently I use something like this:
.row
.col-md-6
.row
.col-md-12
%h4
%strong Title Section One
.row
.col-md-4
%h4
%strong Bold Content
.col-md-4 Content 1
.col-md-4 Content 2
.col-md-4 Content 3
.col-md-6
.row
.col-md-12
%h4
%strong Title Section Two
Is there a way for the "Bold Content" and the "Title Section" parts to be shorten down? Preferably down to a single line? Maybe something close to this:
.col-md-4=%h4=%strong Bold Content
I know I can do use some CSS classes and/or IDs to achieve this, but I was wondering if HAML had a way to avoid making several indentation levels for a single line of content.
You can't do it with HAML syntax, but HAML lets you embed HTML:
.col-md-4 <h4><strong>Bold Content</strong></h4>
I'm using Django+Markdown for processing user input. Text produced by the markdown filter need to be 'safe' and is not protected by django's auto-escape mechanism, so I have to escape user input myself. This is how I do it now:
{{ text|force_escape|markdown:"codehilite" }}
However, if text contains something that would be marked as <code> by markdown, it is escaped as well and the output would be pretty ugly(e.g., '<' is displayed as < in <code>). For example, if
text = u'''
<script>alert("I'm not working 'cause I'll be escaped")</script>
The following would be marked as a code block:
<script>alert("not xss 'cause I'm in <code>")</script>
'''
Using the filter mentioned above, the produced text is:
<p>
<script>alert("I'm not working 'cause I'll be escaped")</script>
The following would be marked as a code block:
</p>
<pre class="codehilite">
<code>
<script>alert("not xss 'cause I'm in <code>")</script>
</code>
</pre>
What I what is:
<p>
<script>alert("I'm not working 'cause I'll be escaped")</script>
The following would be marked as a code block:
</p>
<pre class="codehilite">
<code>
<script>alert("not xss 'cause I'm in <code>")</script>
</code>
</pre>
I'm thinking about using BeautifulSoup to get the <code> blocks produced by markdown and reverse-escape their content. But soup.code.text returns only the 'text', excluding the tags. so I couldn't get my hands on any of the <,>,',",&s in it..
Don't escape the input before passing it to Markdown. As you found, this breaks user input in some cases. And, it doesn't ensure security: consider, e.g., "[clickme](javascript:alert%28%22xss%22%29)".
Instead, the correct approach is to use Markdown in its safe mode. I've written elsewhere about how to do so, but the short version in Django is to use something like {{ text | markdown:"safe" }}. (Alternatively, you can apply a HTML sanitizer, like HTML Purifier, to the output of the Markdown processor.)