diff --git a/core/modules/widgets/element.js b/core/modules/widgets/element.js index 4bfbe53ad..b76e37b00 100755 --- a/core/modules/widgets/element.js +++ b/core/modules/widgets/element.js @@ -35,6 +35,14 @@ ElementWidget.prototype.render = function(parent,nextSibling) { if($tw.config.htmlUnsafeElements.indexOf(tag) !== -1) { tag = "safe-" + tag; } + // Adjust headings by the current base level + var headingLevel = ["h1","h2","h3","h4","h5","h6"].indexOf(tag); + if(headingLevel !== -1) { + var baseLevel = parseInt(this.getVariable("tv-adjust-heading-level","0"),10) || 0; + headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6); + tag = "h" + headingLevel; + } + // Create the DOM node var domNode = this.document.createElementNS(this.namespace,tag); this.assignAttributes(domNode,{excludeEventAttributes: true}); parent.insertBefore(domNode,nextSibling); diff --git a/editions/tw5.com/tiddlers/variables/examples/Sample Headings 1-2-3.tid b/editions/tw5.com/tiddlers/variables/examples/Sample Headings 1-2-3.tid new file mode 100644 index 000000000..97a5e97bc --- /dev/null +++ b/editions/tw5.com/tiddlers/variables/examples/Sample Headings 1-2-3.tid @@ -0,0 +1,22 @@ +created: 20180609112450207 +modified: 20180609112450207 +title: Sample Headings 1,2,3 + +! This is a Level 1 Heading + +This is a paragraph. + +<$vars tv-adjust-heading-level="-2"> + +{{Sample Headings 3,4,5}} + + + +!! This is a Level 2 heading + +<$vars tv-adjust-heading-level="-1"> + +{{Sample Headings 4,5,6}} + + + diff --git a/editions/tw5.com/tiddlers/variables/examples/Sample Headings 3-4-5.tid b/editions/tw5.com/tiddlers/variables/examples/Sample Headings 3-4-5.tid new file mode 100644 index 000000000..214218363 --- /dev/null +++ b/editions/tw5.com/tiddlers/variables/examples/Sample Headings 3-4-5.tid @@ -0,0 +1,9 @@ +created: 20180609112450207 +modified: 20180609112450207 +title: Sample Headings 3,4,5 + +!!! This is written as a Level 3 heading + +!!!! This is written as a Level 4 heading + +!!!!! This is written as a Level 5 heading diff --git a/editions/tw5.com/tiddlers/variables/examples/Sample Headings 4-5-6.tid b/editions/tw5.com/tiddlers/variables/examples/Sample Headings 4-5-6.tid new file mode 100644 index 000000000..eb67694dd --- /dev/null +++ b/editions/tw5.com/tiddlers/variables/examples/Sample Headings 4-5-6.tid @@ -0,0 +1,9 @@ +created: 20180609112450207 +modified: 20180609112450207 +title: Sample Headings 4,5,6 + +!!!! This is written as a Level 4 heading + +!!!!! This is written as a Level 5 heading + +!!!!!! This is written as a Level 6 heading diff --git a/editions/tw5.com/tiddlers/variables/examples/tv-adjust-heading-level.tid b/editions/tw5.com/tiddlers/variables/examples/tv-adjust-heading-level.tid new file mode 100644 index 000000000..a7a13ae25 --- /dev/null +++ b/editions/tw5.com/tiddlers/variables/examples/tv-adjust-heading-level.tid @@ -0,0 +1,25 @@ +created: 20180609112450207 +modified: 20180609112450207 +tags: [[tv-adjust-heading-level Variable]] [[Variable Examples]] +title: tv-adjust-heading-level Variable (Examples) +type: text/vnd.tiddlywiki + +\define show-tiddler(title) +!! $title$ + +<$codeblock code={{$title$}}/> +\end + +! Tiddlers + +<> + +<> + +<> + +! Example + +<$macrocall $name=".example" n="1" +eg="""<$transclude tiddler="Sample Headings 1,2,3" mode="block"/>"""/> + diff --git a/editions/tw5.com/tiddlers/variables/tv-adjust-heading-level Variable.tid b/editions/tw5.com/tiddlers/variables/tv-adjust-heading-level Variable.tid new file mode 100644 index 000000000..161c3b42c --- /dev/null +++ b/editions/tw5.com/tiddlers/variables/tv-adjust-heading-level Variable.tid @@ -0,0 +1,12 @@ +caption: tv-adjust-heading-level +created: 20180609112450207 +modified: 20180609112450207 +tags: Variables [[Core Variables]] [[Configuration Variables]] +title: tv-adjust-heading-level Variable +type: text/vnd.tiddlywiki + +The <<.def tv-adjust-heading-level>> [[variable|Variables]] allows the level of [[headings|Headings in WikiText]] to be adjusted. It is interpreted as a positive or negative number (e.g. "2" or "-3") that is added to the heading level for display. + +Note that if the resulting heading level is less than 1 then level 1 is used instead. This means that specfiying a large negative adjustment factor will reset all headings to display as level 1. Similarly, heading levels larger than 6 are clamped to the maximum HTML heading level of 6. + +<<.variable-examples "tv-adjust-heading-level">>