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
Comment #1
migmedia commentedWhat 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
Comment #2
fangel commentedMigmedia: Yes, but then the markdown layout will be gone.
Example imput:
With full Markdown plus ul/li's as not allowed tags, the output will be
Because
Will be transformed into
Which will render as the above mentioned
A List Herebecause HTML collapses whitespaceWith 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
Comment #3
barraponto@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.
Comment #4
fangel commentedWell, 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.
Comment #5
barrapontoI 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.
Comment #6
barrapontoSorry 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
Comment #7
barrapontoI 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.
Comment #8
barrapontoHere's an updated patch. I think the original patch sneaks in a
static $parsersto 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.
Comment #9
barrapontoOf course, I forgot the patch.
Comment #10
barrapontoRolling against 7.x-2.x
Comment #11
frjo commented