mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-09-12 15:56:05 +00:00
Add support for \dir pragma
This commit is contained in:
51
core/modules/parsers/wikiparser/rules/dir.js
Normal file
51
core/modules/parsers/wikiparser/rules/dir.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/*\
|
||||
title: $:/core/modules/parsers/wikiparser/rules/dir.js
|
||||
type: application/javascript
|
||||
module-type: wikirule
|
||||
|
||||
Wiki pragma rule for specifying text direction
|
||||
|
||||
```
|
||||
\dir rtl
|
||||
\dir ltr
|
||||
\dir auto
|
||||
```
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.name = "dir";
|
||||
exports.types = {pragma: true};
|
||||
|
||||
/*
|
||||
Instantiate parse rule
|
||||
*/
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /^\\dir[^\S\n]*(\S+)\r?\n/mg;
|
||||
};
|
||||
|
||||
/*
|
||||
Parse the most recent match
|
||||
*/
|
||||
exports.parse = function() {
|
||||
var self = this;
|
||||
// Move past the pragma invocation
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Parse tree nodes to return
|
||||
return [{
|
||||
type: "element",
|
||||
tag: this.parser.parseAsInline ? "span" : "div",
|
||||
attributes: {
|
||||
dir: {type: "string", value: this.match[1]}
|
||||
},
|
||||
children: []
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
@@ -27,6 +27,7 @@ Attributes are stored as hashmaps of the following objects:
|
||||
|
||||
var WikiParser = function(type,text,options) {
|
||||
this.wiki = options.wiki;
|
||||
this.parseAsInline = options.parseAsInline;
|
||||
var self = this;
|
||||
// Check for an externally linked tiddler
|
||||
if($tw.browser && (text || "") === "" && options._canonical_uri) {
|
||||
@@ -63,7 +64,7 @@ var WikiParser = function(type,text,options) {
|
||||
this.tree = [];
|
||||
var topBranch = this.parsePragmas();
|
||||
// Parse the text into inline runs or blocks
|
||||
if(options.parseAsInline) {
|
||||
if(this.parseAsInline) {
|
||||
topBranch.push.apply(topBranch,this.parseInlineRun());
|
||||
} else {
|
||||
topBranch.push.apply(topBranch,this.parseBlocks());
|
||||
|
11
editions/tw5.com/tiddlers/Right-To-Left Languages.tid
Normal file
11
editions/tw5.com/tiddlers/Right-To-Left Languages.tid
Normal file
@@ -0,0 +1,11 @@
|
||||
created: 20200406151830903
|
||||
modified: 20200406152521698
|
||||
title: Right-To-Left Languages
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
<<.from-version "5.1.22">> The [[language plugins|Languages]] in TiddlyWiki's plugin library apply the appropriate [["right-to-left" setting|https://www.w3.org/International/questions/qa-html-dir]] to the entire document. To set the right to left setting independently for an individual tiddler, use the `\dir` [[pragma|Pragma]] at the top of the tiddler:
|
||||
|
||||
```
|
||||
\dir rtl
|
||||
This text will be displayed with right-to-left formatting
|
||||
```
|
@@ -1,5 +1,5 @@
|
||||
created: 20150219175930000
|
||||
modified: 20180928145730028
|
||||
modified: 20200406151829696
|
||||
tags: Concepts
|
||||
title: Pragma
|
||||
type: text/vnd.tiddlywiki
|
||||
@@ -18,3 +18,7 @@ The following pragmas are available:
|
||||
: <<.from-version "5.1.15">> Control whether whitespace is trimmed from the start and end of text runs (the default is ''notrim''). This setting can be useful when the whitespace generated by linebreaks disturbs formatting
|
||||
;`\import <filter-expression>`
|
||||
: <<.from-version "5.1.18">> for importing macro definitions from tiddlers identified by a filter expression
|
||||
;`\dir ltr`
|
||||
;`\dir rtl`
|
||||
;`\dir auto`
|
||||
: <<.from-version "5.1.22">> for setting the text direction of a tiddler -- see [[Right-To-Left Languages]].
|
||||
|
Reference in New Issue
Block a user