createRemoveWordWrapInputProcessor

Type: Function

How to get createRemoveWordWrapInputProcessor?

JavaScript

import createRemoveWordWrapInputProcessor from 'fontoxml-pipelined-importer/src/createRemoveWordWrapInputProcessor.js'

Since flat, imported content may add wordwrapping, we could remove it.

Example use:

To remove softWraps like the following:

Other

 - somethingSomethin bladiblah\r\n // Recognized as list
   Even more bladiblah\r\n
   End of listItem somewhere here;
 - A new List Item, bladiblah
   bladibladiblah.

A wordWrapRemover like the following will work:

JavaScript

createWordWrapRemover('ListItem', /[\.;]\s*$/) // ListItem ends with an semicolon or
a dot with zero or more spaces

The resulting function will, given the following input:

JavaScript

[{labels: [
		'ListItem'
	],
	text: '- somethingSomethin bladiblah'
}, {
	labels: [],
	text: 'Even more bladiblah'
}, ...
{
	labels: [],
	text: 'bladibladiblah. '
}]

The following chunks will be returned:
[{labels: [
		'ListItem'
	],
	text: '- somethingSomethin bladiblah Even more bladiblah End of listItem somewhere here;'
}, {
	labels: ['ListItem'],
	text: '- A new List Item, bladiblah, bladibladiblah. '
}]

Also, the following wordWrappers are valid:

JavaScript

createWordWrapRemover(null, \.\) // All chunk should end with a dot
createWordWrapRemover(
	function (chunk) {return /^\W/.test(chunk.text);},  // A chunk starting with a capital letter ...
	function (chunk) {return chunk.text.length < 20 || chunk.text.endsWith('.');} // ... is terminated by a short line or a point
);

Arguments

  1. chunkStartSpec

    (Required)

    Type: String | Array<String> | Function | NULL

    The matcher for label of the start of the chunk. All next chunks will be merged into this one, until the stopping spec tells to stop. Regexp specs will be matched to the label, function specs will be passed the whole chunk. Null specs will always match.

  2. chunkEndSpec

    (Required)

    Type: RegExp | Function

    The stopping condition for the end of the wrapped chunks. Regexp specs will be test against the text of the chunk. The whole chunk is passed if the spec is a function If true, the given chunk will be the last which will be merged.

  3. chunkJoiningString

    (Required)

    Type: String

    The string which should be placed to join the chunks

Returns