Hi,

We wanted to use Markdown for our formatting, but found that we didn't want to allow e.g. headings and images in comments, so we searched for a way to disable specific parts of Markdown.

I came up with a fairly non-intrusive way of doing it, by removing the relevant gamuts from an instance of the parser classes, before using it to parse the incoming text.

Attached is a patch that has switches for disabling/enabling headings, tables, lists and images. It can easily be extended to cover other functionality, as long as the functionality is handled by a gamut in the parser..

Regards
Morten

Comments

migmedia’s picture

What about adding "Limit allowed HTML tags"-Filter as last point in input-filter-chain?

You can remove any HTML-Entity you want, without coding...

Micha

fangel’s picture

Migmedia: Yes, but then the markdown layout will be gone.

Example imput:

 - A
 - List
 - Here

With full Markdown plus ul/li's as not allowed tags, the output will be

A List Here

Because

<ul>
<li>A</li>
<li>List</li>
<li>Here</li>
</ul>

Will be transformed into


A
List
Here

Which will render as the above mentioned A List Here because HTML collapses whitespace

With my patch, and lists not allowed, the markup returned should be unchanged, and hence still resemble a list, just not a html unordered list.

So I believe my patch has a use :)

-Morten

barraponto’s picture

Status: Needs review » Needs work

@fangel: your patch makes perfect sense, but for backward compatiblity I believe the settings should disable the gamut instead of enabling them. It would thus leave them enabled by default.

BTW, the static $parsers array is good for performance.

fangel’s picture

Well, the default setting for new filters should have all the gamuts enabled - but there is possibly a issue with existing filters that don't have the gamuts enabled.

So yeah, there should probably be a check if the settings are absent, and then assume the default, enabled, settings.

barraponto’s picture

I guess I warned before I actually read the code. As far as I can see, the defaults will be loaded on the form and will be used. I'll try it out and set it as RTBC if I think it's appliable as is to 7.x-1.x.

barraponto’s picture

StatusFileSize
new3.55 KB

Sorry for taking so long, I just got the time to reroll the patch. Please follow Drupal patch guide, it makes mantainers' work a lot easier: http://drupal.org/node/707484

barraponto’s picture

I like this. However I don't know why only those gamuts are exposed, and not all. Actually, I know: an overcrowded filter settings screen would suck. But nevertheless, I fail to understand the rationale behind the choice.

For completeness, here is the list (and a tidbit of a rationale):

Markdown:
stripLinkDefinitions => would break links if A tag is not allowed, but wouldn't affect text content. No settings needed.
runBasicBlockGamut => no idea, better not exposed. :P
doHeaders => would break HTML formatting if H1-6 is disabled. Settings needed.
doHorizontal Rules => would disappear if HR is disabled, which is expected. No settings needed.
doLists => would break HTML formatting if UL/OL/LI is disabled. Settings needed.
doCodeBlocks => would break HTML formatting if PRE is disabled. Settings needed.
doBlockQuotes => would break HTML formatting if blockquotes are disabled. Settings needed.
parseSpan => nothing would break (everything is inline). No settings needed.
doImages => would disappear if IMG are disabled, which is expected. But I'd rather output the alt content, if any. No settings needed.
doAnchors => would break links if A tag is not allowed, but wouldn't affect text content. No settings needed.
doAutoLinks => would break links if A tag is not allowed, but wouldn't affect text content. No settings needed.
encodeAmpsAndAngles => unrelated.
doItalicsAndBold => nothing would break (everything is inline). No settings needed.
doHardBreaks => would disappear if BR is disabled, as expected.

MarkdownExtra:
doFencedCodeBlocks => would break HTML formatting if PRE is disabled. Settings needed.
stripFootnotes => would break links if A tag is not allowed, but wouldn't affect text content. No settings needed.
stripAbbreviations => nothing would break (everything is inline). No settings needed.
appendFootnotes => would break numbers if OL/LI is disabled. Settings needed.
doFencedCodeBlocks => would break HTML formatting if PRE is disabled. Settings needed.
doTables => would break HTML formatting if TABLE/TR/TD is disabled. Settings needed.
doDefLists => would break HTML formatting if DL/DT/DD is disabled. Settings needed.
doFootnotes => would break numbers if OL/LI is disabled. Settings needed.
doAbbreviations => => nothing would break (everything is inline). No settings needed.

barraponto’s picture

Here's an updated patch. I think the original patch sneaks in a static $parsers to speed up things, which I left in. I broke deflists settings from lists settings, since they might be disabled separately, added footnotes settings to lists settings since they depend on OL tags, added blockquote and code snippets settings.

Oh, and removed image settings since they would just disappear if they're forbidden.
Also, I've let them enabled by default, check to disable.

Please, test and review this patch. Breaking Markdown settings from Markdown Extra settings is a separate followup issue.

barraponto’s picture

Status: Needs work » Needs review
StatusFileSize
new5.37 KB

Of course, I forgot the patch.

barraponto’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Rolling against 7.x-2.x

frjo’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)