Is it possible to invert camelcase in liquid? - jekyll

How can I split word 'CamelCaseWord' in liquid to 'Camel Case Word'?

With liquid filter available in Jekyll 3.1.x, it's not possible.
But you can create a new liquid filter plugin.

Related

Why csv-table can not skip pages in sphinx-doc

I use sphinx to generate PDF files,but when I use csv-table to generate pdf,I found the generated csv-table could not skip pages automatically? How do I fix it?
You might want to try the Sphinx builder included with rinohtype, which offers a drop-in replacement for the LaTeX builder.
rinohtype will split your tables across pages. It can also automatically size table column widths, unlike the LaTeX builder. Another advantage is that rinohtype's PDF output can be styled more easily by means of CSS-like style sheets in case you need this.
(Full disclosure: I am the author of rinohtype)
I solved this problem by adding the class longtable
.. csv-table::
:file: path-to-csv-file
:class: longtable

How to set an empty attribute using Jade?

When using jade, AngularJs and angular-translate I prefer to use the translate directive as an empty attribute.
But for some reason, when using empty attributes in Jade, instead of getting something like <tag translate OR <tag translate='', I'm getting <tag translate='translate'
How can I add an attribute without a value?
The answer is to use the {doctype: "html"} when using the Pug (before was Jade) template engine.
This option has been documented recently, but it does not states what is it for.
Bear in mind that since I'm just processing all the jade files using gulp, I don't care that much about partials and such things...
Caveats: as stated by #lmacsen at github:
This fail if you need to use that code into a partial html file.
I've come up with this answer after reading several other github issues in the project page.
https://github.com/pugjs/pug/issues/201#issuecomment-1530205
https://github.com/pugjs/pug/issues/1180
I'm Using .foo(bar="") and it produces <div bar class="foo"></div>.
Using .foo(bar) you will get <div bar="bar" class="foo"></div>.
I'm Using most recent versions of Pug (formerly known as Jade) and I'm also using Partial jade files.

Is it possible to pull metadata from JSON into a markdown file? [duplicate]

I have an object from the database with some markdown markup I would like to render with jade. But how? When I apply the :markdown filter I can't use the object as object anymore, but it get's treated as text.
I started here:
p
:markdown
entry.content
Which renders to plain:
entry.content
So I tried putting = and - in front or wrapping #{} arround it. Is it possible at all?
I found a simple way of doing this, as explained in this answer. It uses marked library so first install it.
$ npm install marked --save
In router page
var markdown = require('marked');
var text = '**new text**';
res.render('template', {text:text, markdown:markdown});
In template.jade, try any of following lines
!= markdown(text);
p!= markdown(text);
This is cleanest way of implementing dynamic filters for markdown, in my opinion.
Filters are compile-time, so if you want to run a markdown filter on a run-time variable, you'll have to render the markdown yourself and pass it to your jade view:
https://groups.google.com/forum/?fromgroups=#!topic/express-js/8H4HNcoeekk

can I customize a html|raw in twig

I am looking to secure some wysiwyg input in a symfony2 application, I have been looking at some flat php plugins like htmlpurifier but just tweaking the twig standard functionality like variable|raw_secure with some own parameters would suffice, if there is a way to create a filter that inherits from the |raw but lets me specify a few tags that are allowed...
Anyone done that?
I need to protect myself from xss, javascripts etc.
“if there is a way to create a filter that inherits from the |raw but lets me specify a few tags that are allowed...”
Twig's filter raw does nothing with parameter passed to it.
You can use Twig's filter escape with specific strategy. If that solution doesn't fit – you can create your own Twig filter.

How do I reuse HTML snippets in a django view

I am working on a django project (my first), and in one of my views, I have a sophisticated html snippet with JS weaved within it. I would like to reuse this "component" somewhere else in the same view. Is there a way of achieving this? Please let me know if this design is faulty to begin with?
Use the {% include '/my/common/template.html' %} templatetag.
Loads a template and renders it with
the current context. This is a way of
"including" other templates within a
template.
The template name can either be a
variable or a hard-coded (quoted)
string, in either single or double
quotes.
I know it's an old one but maybe someone is gonna have use of this answer.
There's also the inclusion tag. It's like the include tag, only you can pass it arguments and process it as a seperate template.
Put this in my_app/templatetags/my_templatetags.py:
#register.inclusion_tag('my_snippet.html')
def my_snippet(url, title):
return {'url': url, 'title': title}
and then my_snippet.html can be:
{{ title }}
then, to use this snippet in your templates:
{% load my_templatetags %}
{% my_snippet "/homepage/" "Homepage" %}
More info:
https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags-inclusion-tags
Not sure, if you like to reuse your HTML in different templates (rendered by different views). If so, look into Django's template inheritance mechanism:
The most powerful -- and thus the most complex -- part of Django's template engine is template inheritance. Template inheritance allows you to build a base "skeleton" template that contains all the common elements of your site and defines blocks that child templates can override.
You should try Django custom template tags. This way you will keep your snippets in an external file and then call them easily by something like {{ your_custom_tag }}. It's a very convenient method for working with reusable chunks of xhtml markup. You can even use arguments with these custom tags, something like {{ your_custom_tag|image:"logo.png" }}.
You can learn more about custom tags here.