QuoteToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki

Table of Contents

Other Languages

Introduction

Single quotes (italic or bold). This class inherits all the properties and methods of the Token class which are not repeated here.

✅ Available in the Mini and Browser versions.
🌐 Available in the Browser version.

Properties

bold

✅ Expand

version added:1.3.9

type: boolean
Whether it is bold.

// bold
var {firstChild} = Parser.parse("'''");
assert.ok(firstChild.bold);

italic

✅ Expand

version added:1.3.9

type: boolean
Whether it is italic.

// italic
var {firstChild} = Parser.parse("''");
assert.ok(firstChild.italic);

closing

Expand

version added:1.16.5

type: {bold?: boolean, italic?: boolean}
Whether it is a closing <b>/<i> tag.

// closing (main)
var {firstChild} = Parser.parse("''");
assert.deepStrictEqual(firstChild.closing, {italic: false});

Methods

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var {firstChild: {firstChild: {lastChild}}} = Parser.parse("==''''==");
assert.equal(lastChild, "'''");
assert.deepStrictEqual(lastChild.lint(), [
	{
		rule: 'lonely-apos',
		severity: 'warning',
		message: `lonely "'"`,
		startLine: 0,
		startCol: 2,
		startIndex: 2,
		endLine: 0,
		endCol: 3,
		endIndex: 3,
		suggestions: [
			{
				desc: 'escape',
				range: [2, 3],
				text: '&apos;',
			},
			{
				desc: 'remove',
				range: [2, 3],
				text: '',
			},
		],
	},
	{
		rule: 'bold-header',
		severity: 'warning',
		message: 'bold text in a section header',
		startLine: 0,
		startCol: 3,
		startIndex: 3,
		endLine: 0,
		endCol: 6,
		endIndex: 6,
		suggestions: [
			{
				desc: 'remove',
				range: [3, 6],
				text: '',
			},
		],
	},
]);

json

🌐 Expand

Save the syntax tree as JSON.

// json (print)
var {lastChild} = Parser.parse(" ''");
assert.deepStrictEqual(lastChild.json(), {
	range: [1, 3],
	type: 'quote',
	bold: false,
	italic: true,
	childNodes: [
		{
			range: [1, 3],
			data: "''",
		},
	],
});

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var {firstChild} = Parser.parse("''");
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);

findMatchingQuote

Expand

version added: 1.29.3

param 'bold' | 'italic' type of apostrophes to find
returns: this | undefined
Find the matching apostrophes for the given type.

// findMatchingQuote (self)
var {firstChild, lastChild} = Parser.parse("'''''a'''");
assert.equal(firstChild, "'''''");
assert.equal(lastChild, "'''");
assert.strictEqual(firstChild.findMatchingQuote('bold'), lastChild);
assert.strictEqual(firstChild.findMatchingQuote('italic'), undefined);
assert.strictEqual(lastChild.findMatchingQuote(), firstChild);

getRange

Expand

version added: 1.29.3

param 'bold' | 'italic' type of apostrophes to find
returns: AstRange | undefined
Try to get the range of bold/italic text.

// getRange (self)
var {firstChild, lastChild} = Parser.parse("'''''a'''");
assert.equal(firstChild, "'''''");
assert.equal(lastChild, "'''");
assert.equal(firstChild.getRange('bold'), 'a');
assert.strictEqual(firstChild.getRange('italic'), undefined);
assert.equal(lastChild.getRange(), 'a');
⚠️ **GitHub.com Fallback** ⚠️