createRemoveWordWrapInputProcessor

How to get createRemoveWordWrapInputProcessor

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

Type: Function

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

Example use:

To remove softWraps like the following:

 - 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:

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

The resulting function will, given the following input:

[{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:

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

# Name Type Description
1. chunkStartSpec
2. chunkEndSpec 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 String

The string which should be placed to join the chunks

Was this page helpful?