Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-04-23 14:30:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

[textile] Code in a figure

I’m trying to work out the simplest way for people to present Textpattern code blocks inside <figure> tags with <figcaption>. No matter what I do, Textile gets in the way and I’m running out of straws to clutch at. Turning off Textile for the articles is not an option, as the surrounding content needs to be Textiled.

If I could somehow wrap the procedure up in a <txp:output_form> with <txp:yield> or, better, an smd_macro I’d be really happy but I can’t get the content to be passed to the form or macro without Textile mangling it. The code itself will probably be coloured with Google Code Prettify so I’m using the latest bleeding edge Textile to benefit from the bc(class).. only being applied to the wrapped <pre> tag.

Closest so far is this horrible hunk of typing:

<figure>

 bc(prettyprint).. <!-- description of code here -->
<txp:some_tag atts="go here">
...
</txp:some_tag>

<txp:other_tag atts="more here">
...
</txp:other_tag>

 p. <figcaption>Figure 1: Some caption.</figcaption>
</figure>

(note I had to add a preceding space to the bc(prettyprint).. and p. to prevent the forum exiting the code block: they’re not actually necessary)

That renders the content exactly as I want, but it’s not very friendly for users to remember the line breaks and escaping the figcaption, etc, so my aim is to simplify the process to reduce the amount of typing or potential for errors to creep in.

Bizarrely if I try to bypass Textile and use all HTML by escaping the entire block with notextile.., or == wrappers, or a leading space:

notextile.. <figure>
<pre class="prettyprint"><!-- description of code here -->
<txp:some_tag atts="go here">
...
</txp:some_tag>

<txp:other_tag atts="more here">
...
</txp:other_tag>
</pre>
<figcaption>Figure 1: Some caption.</figcaption>
</figure>

I get no output in the code block. Textile just swallows the code (presumably it executes it on article save for some reason).

This would be my ideal scenario (a macro), but I can’t get it to work:

<txp:codeblock caption="Figure 1: Some caption.">
<!-- description of code here -->
<txp:some_tag atts="go here">
...
</txp:some_tag>

<txp:other_tag atts="more here">
...
</txp:other_tag>
</txp:codeblock>

Can anyone think of any cunning ways to wrap Textpattern code (multi-line, with line breaks) in a figure inside an article such that people writing articles won’t run a mile when they see the necessary syntax? Perhaps some way of using square brackets to swallow the spaces might work, but I’m stumped. Thanks.

Last edited by Bloke (2012-04-23 14:34:45)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2012-04-23 14:40:13

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [textile] Code in a figure

You said turning off Textile for that article is not an option. But what if… you turn it off!
And then, for the chunks of content to be textilized, you wrap them with smd_wrap or upm_textile. Maybe even you could keep the people writing articles away from smd_wrap or upm_textile… by using smd_macro.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2012-04-23 14:54:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: [textile] Code in a figure

maniqui wrote:

You said turning off Textile for that article is not an option. But what if… you turn it off!

Well, I suppose in that light then yes it’s an option. In my current test article for instance, there are 5 such code blocks so I’d need:

<txp:smd_wrap transform="textile">content blah blah</txp:smd_wrap>
<figure>
Txp code
<figcaption>Caption</figcaption>
</figure>
<txp:smd_wrap transform="textile">more content</txp:smd_wrap>
<figure>
Txp code
<figcaption>Caption</figcaption>
</figure>
<txp:smd_wrap ...

Still wordier than I’d like, but you’re right that at least the code will render! Just can’t help thinking I’m missing some obvious Textile trick that’ll make this possible as a neat macro.

Last edited by Bloke (2012-04-23 14:55:08)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2012-04-23 15:01:35

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [textile] Code in a figure

Maybe there is something for you in this branch.

github.com/netcarver/textile/tree/feature-block-plugins

It was an idea I shared with Steve, about having user-defined Textile macros.
I think it may even have inspired you to create smd_macros…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2012-04-23 15:04:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: [textile] Code in a figure

Incidentally, I’ve had success writing the code as a gist and pulling it into the article using a macro:

<txp:gist id="12345678">Figure 1: some caption.</txp:gist>

Brilliant! But has a few major drawbacks:

  1. The code has to be written off-site as a public gist. It can’t be written as a private gist and then converted to a public one at publication time (well, it can but it involves creating a new gist ID anyway and doing some pull-push trickery, so the advantage to having the ID embedded in the article prior to publication without revealing the content of the gist itself is lost).
  2. There’s no Textpattern syntax highlighter, and the default PHP / HTML / PHTML highlighters don’t cope with tags-in-tags very well. GCP manages to colour them nicely using the default HTML renderer.

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2012-04-23 15:05:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: [textile] Code in a figure

maniqui wrote:

Maybe there is something for you in this branch.

Mmmm bcphp. Tasty, yet experimental. Do I risk it on a live site….? And will it work with Textpattern tags? Nope :-( It requires a custom Textile macro.

Last edited by Bloke (2012-04-23 15:09:51)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2012-04-23 16:12:20

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: [textile] Code in a figure

Bloke wrote:

Mmmm bcphp. Tasty, yet experimental. Do I risk it on a live site….? And will it work with Textpattern tags? Nope :-( It requires a custom Textile macro.

And not recommended for anything other than testing. There have been some bug-fixes committed to the master branch since that was forked; you definitely don’t want to be using it on a live site.


Steve

Offline

#8 2012-04-23 17:10:52

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: [textile] Code in a figure

Have you try with the no textile code (==)? equalequal your code equalequal.

…Sorry. Now reading again your initial post I see you have tried it yet. No ideas then

Last edited by milosevic (2012-04-23 17:17:33)


<txp:rocks/>

Offline

Board footer

Powered by FluxBB