How to filter the html markups when render a template with jinja2? - django

Now I'm biulding a django project with jinja2 dealing with templates. Some page contents are submited by the client with wysiwy editor, and thing's going fine with the detail pages.
But the list pages are wrong with the slice of the contents.
My code:
<div class="summary ">
<div class="content">{{ question.content[:200]|e}}...</div>
</div>
But the output is:
<p>what i want to show here is raw text without markups</p>...
The expected result is that the html markups like <p></p> <section>.... are gone (filtered or eliminated) and only the raw text shows!
So how can I fix it? Thanks in advance!

Use striptags filter:
striptags(value)
Strip SGML/XML tags and replace adjacent whitespace
by one space.
<div class="content">{{ question.content|striptags}}...</div>
Jinja2 striptags filter test will also help you to understand how it works.
Hope that helps.

Related

Bootstrap group list shows text sprites at runtime

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.

Regex for HTML RESPONSE BODY present under div tag

I need to build a regex for extracting the value present under value field.
i.e "f70a8c3d0a6cbe2e235c7fd1dd27d052df7412ea"
HTML RESPONSE BODY :
Note: I have pasted just a minor part of the response....but formToken key is unique
<div class="hidden">
<input name="formToken type="hidden"
value="f70a8c3d0a6cbe2e235c7fd1dd27d052df7412ea"
/>
</div>
I wrote the below regex but it returned nothing:
regex("formToken" type="hidden" value="([^"]*)"/>).find(0).exists, found nothing
Can you try this?
regex("type="hidden".*value="(.*?)[ \t]*"/>).find(0).exists
Instead of a regex, you could use a css selector check which is probably way easier once you have ids or css classes to search for.
Thank you all....I was able to get formToken using css
.check(css("input[name='formToken']", "value").saveAs("formTokex"))
Works like this for me:
.exec(http("request_1")
.get("<<<<YOUR_URL>>>>>")
.check(css("form[name='signInForm']", "action").saveAs("urlPath"))
and later printing it:
println(session( "urlPath" ).as[String])

Bluecloth: markdown to HTML results in lots of empty tags

For example, the following markdown:
# Game Version
Need For Speed Most Wanted v1.3 English version.
Results in the following HTML:
<h1>Game Version</h1>
<p></p>
<p></p>
<p>Need For Speed Most Wanted v1.3 English version.</p>
<p></p>
<p></p>
This is even more annoying in lists where every <li></li> is <br><li></li><br>, contrary to the markdown spec. I have checked my markdown and there are no extra end-of-line spaces or anything of the sort. The data is stored as a text field on Heroku Postgres.
Is this a problem with Bluecloth, or am I doing something terribly wrong?
I was actually calling simple_format on the returned string in the view:
simple_format BlueCloth.new(#event.description)
Replacing simple_format with raw fixed the problem.

ModX: Using Ditto with template variables

I am having a great deal of difficulty getting my head round displaying secveral resources on one page with Ditto. I cant seem to get TV's to show along with my content.
Heres how I have set it out:
I have a page with my Ditto call:
[!Ditto? &parents='134' &orderBy='createdon ASC' &tpl='temp'!]
I have a simple chunk called temp set up as such:
<div id="content">
[*articlename*]
[+content+]
</div>
And I have a template with the TV articlename assigned to all the resource under parent 134.
The content shows fine but none of the TV's do. Can anyone point me in the right direction? thanks!
I think the problem is in your syntax. You need to use a placeholder tag in the chunk for your TV:
Try this:
<div id="content"> [+articlename+] [+content+] </div>
I have found the answer: You are meant to use [+articlename+] for 'chunk TVs' rather then [*articlename*]. This is different to getResources.

How to embed <pre> tag in a list in a wiki

I am trying to embed a <pre> tag in within an ordered list, of the form:
# Some content
#: <pre>
Some pre-formatted content
</pre>
But it doesn't work. Can someone please let me know on how to achieve what I am trying to do?
You can use a regular HTML list:
<ol>
<li>Some Content</li>
<li><dl><dd><pre>Some pre-formatted content</pre></dd></dl></li>
</ol>
This is the better answer for continuing a numbered list after using the <pre> tag without resorting to html:
# one
#:<pre>
#:some stuff
#:some more stuff</pre>
# two
Produces:
1. one
some stuff
some more stuff
2. two