mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 23:55:49 +01:00
Extract inline fragments from HTML markup
This commit is contained in:
parent
acdd1f5b4e
commit
2831423d78
11 changed files with 398 additions and 96 deletions
|
|
@ -69,12 +69,12 @@
|
|||
<script src="./tools/simple-image/dist/bundle.js"></script><!-- Image -->
|
||||
<script src="./tools/delimiter/dist/bundle.js"></script><!-- Delimiter -->
|
||||
<!-- <script src="./tools/list/dist/bundle.js"></script> List -->
|
||||
<script src="./tools/nested-list/dist/nested-list.js"></script><!-- Nested List -->
|
||||
<!-- <script src="./tools/nested-list/dist/nested-list.js"></script><!– Nested List –>-->
|
||||
<script src="./tools/checklist/dist/bundle.js"></script><!-- Checklist -->
|
||||
<script src="./tools/quote/dist/bundle.js"></script><!-- Quote -->
|
||||
<script src="./tools/code/dist/bundle.js"></script><!-- Code -->
|
||||
<script src="./tools/embed/dist/bundle.js"></script><!-- Embed -->
|
||||
<script src="./tools/table/dist/bundle.js"></script><!-- Table -->
|
||||
<!-- <script src="./tools/table/dist/bundle.js"></script><!– Table –>-->
|
||||
<script src="./tools/link/dist/bundle.js"></script><!-- Link -->
|
||||
<script src="./tools/raw/dist/bundle.js"></script><!-- Raw -->
|
||||
<script src="./tools/warning/dist/bundle.js"></script><!-- Warning -->
|
||||
|
|
@ -131,11 +131,11 @@
|
|||
*/
|
||||
image: SimpleImage,
|
||||
|
||||
list: {
|
||||
class: NestedList,
|
||||
inlineToolbar: true,
|
||||
shortcut: 'CMD+SHIFT+L'
|
||||
},
|
||||
// list: {
|
||||
// class: NestedList,
|
||||
// inlineToolbar: true,
|
||||
// shortcut: 'CMD+SHIFT+L'
|
||||
// },
|
||||
|
||||
checklist: {
|
||||
class: Checklist,
|
||||
|
|
@ -176,12 +176,12 @@
|
|||
raw: RawTool,
|
||||
|
||||
embed: Embed,
|
||||
|
||||
table: {
|
||||
class: Table,
|
||||
inlineToolbar: true,
|
||||
shortcut: 'CMD+ALT+T'
|
||||
},
|
||||
//
|
||||
// table: {
|
||||
// class: Table,
|
||||
// inlineToolbar: true,
|
||||
// shortcut: 'CMD+ALT+T'
|
||||
// },
|
||||
|
||||
},
|
||||
|
||||
|
|
@ -194,126 +194,220 @@
|
|||
* Initial Editor data
|
||||
*/
|
||||
data: {
|
||||
blocks: [
|
||||
"time" : 1634414421172,
|
||||
"blocks" : [
|
||||
{
|
||||
id: "zcKCF1S7X8",
|
||||
type: "header",
|
||||
data: {
|
||||
text: "Editor.js",
|
||||
level: 2
|
||||
"id" : "zcKCF1S7X8",
|
||||
"type" : "header",
|
||||
"data" : {
|
||||
"text" : "Editor.js",
|
||||
"level" : 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "b6ji-DvaKb",
|
||||
"type": "paragraph",
|
||||
"data": {
|
||||
"text": "Hey. Meet the new Editor. On this page you can see it in action — try to edit this text. Source code of the page contains the example of connection and configuration."
|
||||
"id" : "b6ji-DvaKb",
|
||||
"type" : "paragraph",
|
||||
"data" : {
|
||||
"text" : "Hey. Meet the new Editor. On this page you can see it in action — try to edit this text. Source code of the page contains the example of connection and configuration."
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "header",
|
||||
id: "7ItVl5biRo",
|
||||
data: {
|
||||
text: "Key features",
|
||||
level: 3
|
||||
"id" : "7ItVl5biRo",
|
||||
"type" : "header",
|
||||
"data" : {
|
||||
"text" : "Key features",
|
||||
"level" : 3
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'list',
|
||||
id: "SSBSguGvP7",
|
||||
data : {
|
||||
items : [
|
||||
"id" : "SSBSguGvP7",
|
||||
"type" : "list",
|
||||
"data" : {
|
||||
"items" : [
|
||||
{
|
||||
content: 'It is a block-styled editor',
|
||||
items: []
|
||||
"content" : "It is a block-styled editor",
|
||||
"items" : []
|
||||
},
|
||||
{
|
||||
content: 'It returns clean data output in JSON',
|
||||
items: []
|
||||
"content" : "It returns clean data output in JSON",
|
||||
"items" : []
|
||||
},
|
||||
{
|
||||
content: 'Designed to be extendable and pluggable with a simple API',
|
||||
items: []
|
||||
"content" : "Designed to be extendable and pluggable with a simple API",
|
||||
"items" : []
|
||||
}
|
||||
],
|
||||
style: 'unordered'
|
||||
"style" : "unordered"
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "header",
|
||||
id: "QZFox1m_ul",
|
||||
data: {
|
||||
text: "What does it mean «block-styled editor»",
|
||||
level: 3
|
||||
"id" : "QZFox1m_ul",
|
||||
"type" : "header",
|
||||
"data" : {
|
||||
"text" : "What does it mean «block-styled editor»",
|
||||
"level" : 3
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'paragraph',
|
||||
id: "bwnFX5LoX7",
|
||||
data : {
|
||||
text : 'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class=\"cdx-marker\">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.'
|
||||
"id" : "bwnFX5LoX7",
|
||||
"type" : "paragraph",
|
||||
"data" : {
|
||||
"text" : "Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor's Core."
|
||||
},
|
||||
"fragments" : {
|
||||
"text" : [
|
||||
{
|
||||
"range" : [
|
||||
123,
|
||||
210
|
||||
],
|
||||
"element" : "MARK",
|
||||
"attributes" : {
|
||||
"class" : "cdx-marker"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'paragraph',
|
||||
id: "mTrPOHAQTe",
|
||||
data : {
|
||||
text : `There are dozens of <a href="https://github.com/editor-js">ready-to-use Blocks</a> and the <a href="https://editorjs.io/creating-a-block-tool">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.`
|
||||
"id" : "mTrPOHAQTe",
|
||||
"type" : "paragraph",
|
||||
"data" : {
|
||||
"text" : "There are dozens of ready-to-use Blocks and the simple API for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games."
|
||||
},
|
||||
"fragments" : {
|
||||
"text" : [
|
||||
{
|
||||
"range" : [
|
||||
20,
|
||||
39
|
||||
],
|
||||
"element" : "A",
|
||||
"attributes" : {
|
||||
"href" : "https://github.com/editor-js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"range" : [
|
||||
48,
|
||||
58
|
||||
],
|
||||
"element" : "A",
|
||||
"attributes" : {
|
||||
"href" : "https://editorjs.io/creating-a-block-tool"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "header",
|
||||
id: "1sYMhUrznu",
|
||||
data: {
|
||||
text: "What does it mean clean data output",
|
||||
level: 3
|
||||
"id" : "1sYMhUrznu",
|
||||
"type" : "header",
|
||||
"data" : {
|
||||
"text" : "What does it mean clean data output",
|
||||
"level" : 3
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'paragraph',
|
||||
id: "jpd7WEXrJG",
|
||||
data : {
|
||||
text : 'Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below'
|
||||
"id" : "jpd7WEXrJG",
|
||||
"type" : "paragraph",
|
||||
"data" : {
|
||||
"text" : "Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below"
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'paragraph',
|
||||
id: "0lOGNUKxqt",
|
||||
data : {
|
||||
text : `Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.`
|
||||
"id" : "0lOGNUKxqt",
|
||||
"type" : "paragraph",
|
||||
"data" : {
|
||||
"text" : "Given data can be used as you want: render with HTML for Web clients, render natively for mobile apps, create markup for Facebook Instant Articles or Google AMP, generate an audio version and so on."
|
||||
},
|
||||
"fragments" : {
|
||||
"text" : [
|
||||
{
|
||||
"range" : [
|
||||
57,
|
||||
68
|
||||
],
|
||||
"element" : "CODE",
|
||||
"attributes" : {
|
||||
"class" : "inline-code"
|
||||
}
|
||||
},
|
||||
{
|
||||
"range" : [
|
||||
90,
|
||||
101
|
||||
],
|
||||
"element" : "CODE",
|
||||
"attributes" : {
|
||||
"class" : "inline-code"
|
||||
}
|
||||
},
|
||||
{
|
||||
"range" : [
|
||||
121,
|
||||
146
|
||||
],
|
||||
"element" : "CODE",
|
||||
"attributes" : {
|
||||
"class" : "inline-code"
|
||||
}
|
||||
},
|
||||
{
|
||||
"range" : [
|
||||
150,
|
||||
160
|
||||
],
|
||||
"element" : "CODE",
|
||||
"attributes" : {
|
||||
"class" : "inline-code"
|
||||
}
|
||||
},
|
||||
{
|
||||
"range" : [
|
||||
174,
|
||||
187
|
||||
],
|
||||
"element" : "CODE",
|
||||
"attributes" : {
|
||||
"class" : "inline-code"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'paragraph',
|
||||
id: "WvX7kBjp0I",
|
||||
data : {
|
||||
text : 'Clean data is useful to sanitize, validate and process on the backend.'
|
||||
"id" : "WvX7kBjp0I",
|
||||
"type" : "paragraph",
|
||||
"data" : {
|
||||
"text" : "Clean data is useful to sanitize, validate and process on the backend."
|
||||
}
|
||||
},
|
||||
{
|
||||
type : 'delimiter',
|
||||
id: "H9LWKQ3NYd",
|
||||
data : {}
|
||||
"id" : "H9LWKQ3NYd",
|
||||
"type" : "delimiter",
|
||||
"data" : {}
|
||||
},
|
||||
{
|
||||
type : 'paragraph',
|
||||
id: "h298akk2Ad",
|
||||
data : {
|
||||
text : 'We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make its core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏'
|
||||
"id" : "h298akk2Ad",
|
||||
"type" : "paragraph",
|
||||
"data" : {
|
||||
"text" : "We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make its core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏"
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'image',
|
||||
id: "9802bjaAA2",
|
||||
data: {
|
||||
url: 'assets/codex2x.png',
|
||||
caption: '',
|
||||
stretched: false,
|
||||
withBorder: true,
|
||||
withBackground: false,
|
||||
"id" : "9802bjaAA2",
|
||||
"type" : "image",
|
||||
"data" : {
|
||||
"url" : "assets/codex2x.png",
|
||||
"caption" : "",
|
||||
"withBorder" : true,
|
||||
"withBackground" : false,
|
||||
"stretched" : false
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
],
|
||||
"version" : "2.23.0-rc.0"
|
||||
},
|
||||
onReady: function(){
|
||||
saveButton.click();
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@
|
|||
"terser-webpack-plugin": "^2.3.6",
|
||||
"ts-loader": "^7.0.1",
|
||||
"tslint": "^6.1.1",
|
||||
"typescript": "3.8.3",
|
||||
"typescript": "4.4.3",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-cli": "^3.3.11"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { BlockToolData, PasteEvent } from '../../../types';
|
|||
import { BlockTuneData } from '../../../types/block-tunes/block-tune-data';
|
||||
import BlockAPI from '../block/api';
|
||||
import { BlockMutationType } from '../../../types/events/block/mutation-type';
|
||||
import { InlineFragment, InlineFragmentsDict, SavedData } from '../../../types/data-formats';
|
||||
|
||||
/**
|
||||
* @typedef {BlockManager} BlockManager
|
||||
|
|
@ -268,6 +269,7 @@ export default class BlockManager extends Module {
|
|||
needToFocus = true,
|
||||
replace = false,
|
||||
tunes = {},
|
||||
fragments,
|
||||
}: {
|
||||
id?: string;
|
||||
tool?: string;
|
||||
|
|
@ -276,6 +278,7 @@ export default class BlockManager extends Module {
|
|||
needToFocus?: boolean;
|
||||
replace?: boolean;
|
||||
tunes?: {[name: string]: BlockTuneData};
|
||||
fragments?: InlineFragmentsDict;
|
||||
} = {}): Block {
|
||||
let newIndex = index;
|
||||
|
||||
|
|
@ -283,6 +286,10 @@ export default class BlockManager extends Module {
|
|||
newIndex = this.currentBlockIndex + (replace ? 0 : 1);
|
||||
}
|
||||
|
||||
if (fragments !== undefined) {
|
||||
data = this.insertInlineFragments(data, fragments);
|
||||
}
|
||||
|
||||
const block = this.composeBlock({
|
||||
id,
|
||||
tool,
|
||||
|
|
@ -318,6 +325,89 @@ export default class BlockManager extends Module {
|
|||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* @param fragmentsDict
|
||||
* @private
|
||||
*/
|
||||
public insertInlineFragments(data: Pick<SavedData, 'data'>, fragmentsDict: InlineFragmentsDict): Pick<SavedData, 'data'> {
|
||||
const insertToString = (str: string, fragments: InlineFragment[]): string => {
|
||||
const template = document.createElement('template');
|
||||
|
||||
template.innerHTML = str;
|
||||
|
||||
const walker = document.createTreeWalker(template.content, NodeFilter.SHOW_TEXT);
|
||||
|
||||
const root = walker.currentNode;
|
||||
|
||||
fragments.forEach(fragment => {
|
||||
let offset = 0;
|
||||
let startOffset = 0;
|
||||
let endOffset = 0;
|
||||
let startNode: Node | null = null;
|
||||
let endNode: Node | null = null;
|
||||
|
||||
while (!startNode || !endNode) {
|
||||
const node = walker.nextNode();
|
||||
|
||||
if (!startNode && offset + node.textContent.length > fragment.range[0]) {
|
||||
startNode = node;
|
||||
startOffset = fragment.range[0] - offset;
|
||||
}
|
||||
|
||||
if (!endNode && offset + node.textContent.length >= fragment.range[1]) {
|
||||
endNode = node;
|
||||
endOffset = fragment.range[1] - offset;
|
||||
}
|
||||
|
||||
offset += node.textContent.length;
|
||||
}
|
||||
|
||||
const range = new Range();
|
||||
|
||||
range.setStart(startNode, startOffset);
|
||||
range.setEnd(endNode, endOffset);
|
||||
|
||||
const element = document.createElement(fragment.element);
|
||||
|
||||
Object.entries(fragment.attributes).map(([name, value]) => element.setAttribute(name, value as string));
|
||||
|
||||
range.surroundContents(element);
|
||||
|
||||
walker.currentNode = root;
|
||||
});
|
||||
|
||||
return template.innerHTML;
|
||||
};
|
||||
|
||||
const insert = (dataToProcess: Record<string, unknown>, fragments: InlineFragmentsDict): Pick<SavedData, 'data'> => {
|
||||
Object
|
||||
.entries(dataToProcess)
|
||||
.forEach(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
dataToProcess[key] = value.map(v => insert(v, fragments[key] as InlineFragmentsDict));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
dataToProcess[key] = insert(value as Record<string, unknown>, fragments[key] as InlineFragmentsDict);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
dataToProcess[key] = insertToString(value, fragments[key] as InlineFragment[]);
|
||||
}
|
||||
});
|
||||
|
||||
return dataToProcess as Pick<SavedData, 'data'>;
|
||||
};
|
||||
|
||||
return insert(data, fragmentsDict);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current working block
|
||||
*
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ export default class Renderer extends Module {
|
|||
*/
|
||||
public async insertBlock(item: OutputBlockData): Promise<void> {
|
||||
const { Tools, BlockManager } = this.Editor;
|
||||
const { type: tool, data, tunes, id } = item;
|
||||
const { type: tool, data, tunes, id, fragments } = item;
|
||||
|
||||
if (Tools.available.has(tool)) {
|
||||
try {
|
||||
|
|
@ -82,6 +82,7 @@ export default class Renderer extends Module {
|
|||
tool,
|
||||
data,
|
||||
tunes,
|
||||
fragments,
|
||||
});
|
||||
} catch (error) {
|
||||
_.log(`Block «${tool}» skipped because of plugins error`, 'warn', data);
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@
|
|||
*/
|
||||
import Module from '../__module';
|
||||
import { OutputData } from '../../../types';
|
||||
import { SavedData, ValidatedData } from '../../../types/data-formats';
|
||||
import { InlineFragment, InlineFragmentsDict, SavedData, ValidatedData } from '../../../types/data-formats';
|
||||
import Block from '../block';
|
||||
import * as _ from '../utils';
|
||||
import { sanitizeBlocks } from '../utils/sanitizer';
|
||||
import $ from '../dom';
|
||||
import { deepSanitize, sanitizeBlocks } from '../utils/sanitizer';
|
||||
|
||||
declare const VERSION: string;
|
||||
|
||||
|
|
@ -43,11 +44,25 @@ export default class Saver extends Module {
|
|||
});
|
||||
|
||||
const extractedData = await Promise.all(chainData) as Array<Pick<SavedData, 'data' | 'tool'>>;
|
||||
const sanitizedData = await sanitizeBlocks(extractedData, (name) => {
|
||||
const sanitizedData = sanitizeBlocks(extractedData, (name) => {
|
||||
return Tools.blockTools.get(name).sanitizeConfig;
|
||||
});
|
||||
const withFragments = sanitizedData.map(savedData => {
|
||||
if (savedData.tool === this.Editor.Tools.stubTool) {
|
||||
return savedData;
|
||||
}
|
||||
|
||||
return this.makeOutput(sanitizedData);
|
||||
const fragments = this.extractInlineFragments(savedData.data);
|
||||
|
||||
savedData.data = deepSanitize(savedData.data, {});
|
||||
|
||||
return {
|
||||
...savedData,
|
||||
fragments,
|
||||
};
|
||||
});
|
||||
|
||||
return this.makeOutput(withFragments);
|
||||
} catch (e) {
|
||||
_.logLabeled(`Saving failed due to the Error %o`, 'error', e);
|
||||
} finally {
|
||||
|
|
@ -83,7 +98,7 @@ export default class Saver extends Module {
|
|||
|
||||
_.log('[Editor.js saving]:', 'groupCollapsed');
|
||||
|
||||
allExtractedData.forEach(({ id, tool, data, tunes, time, isValid }) => {
|
||||
allExtractedData.forEach(({ id, tool, data, tunes, fragments, time, isValid }) => {
|
||||
totalTime += time;
|
||||
|
||||
/**
|
||||
|
|
@ -116,6 +131,9 @@ export default class Saver extends Module {
|
|||
...!_.isEmpty(tunes) && {
|
||||
tunes,
|
||||
},
|
||||
...!_.isEmpty(fragments) && {
|
||||
fragments,
|
||||
},
|
||||
};
|
||||
|
||||
blocks.push(output);
|
||||
|
|
@ -130,4 +148,85 @@ export default class Saver extends Module {
|
|||
version: VERSION,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* @private
|
||||
*/
|
||||
private extractInlineFragments(data: Pick<SavedData, 'data'>): InlineFragmentsDict {
|
||||
const extractFromString = (str: string): InlineFragment[] => {
|
||||
const template = $.make('template') as HTMLTemplateElement;
|
||||
|
||||
template.innerHTML = str;
|
||||
|
||||
const walker = document.createTreeWalker(template.content, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
|
||||
|
||||
let node: Node | null;
|
||||
let offset = 0;
|
||||
const fragments: InlineFragment[] = [];
|
||||
|
||||
while ((node = walker.nextNode()) !== null) {
|
||||
switch (node.nodeType) {
|
||||
case Node.TEXT_NODE:
|
||||
offset += node.textContent.length;
|
||||
break;
|
||||
case Node.ELEMENT_NODE: {
|
||||
const length = node.textContent.length;
|
||||
const fragment: InlineFragment = {
|
||||
range: [offset, offset + length],
|
||||
element: node.nodeName,
|
||||
attributes: Object.fromEntries(Array.from((node as HTMLElement).attributes).map(attr => ([attr.nodeName, attr.nodeValue]))),
|
||||
};
|
||||
|
||||
fragments.push(fragment);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fragments;
|
||||
};
|
||||
|
||||
const extract = (obj: Record<string, unknown>): InlineFragmentsDict => {
|
||||
const result: InlineFragmentsDict = {};
|
||||
|
||||
Object
|
||||
.entries(obj)
|
||||
.forEach(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
const fragments = value.map(v => extract(v)).filter(fragment => Object.keys(fragment).length > 0);
|
||||
|
||||
if (fragments.length > 0) {
|
||||
result[key] = fragments;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
const fragments = extract(obj);
|
||||
|
||||
if (Object.keys(fragments).length > 0) {
|
||||
result[key] = fragments;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
const fragments = extractFromString(value);
|
||||
|
||||
if (fragments.length > 0) {
|
||||
result[key] = fragments;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return extract(data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ export function clean(taintString: string, customConfig: SanitizerConfig = {} as
|
|||
* @param {BlockToolData|object|*} dataToSanitize - taint string or object/array that contains taint string
|
||||
* @param {SanitizerConfig} rules - object with sanitizer rules
|
||||
*/
|
||||
function deepSanitize(dataToSanitize: object | string, rules: SanitizerConfig): object | string {
|
||||
export function deepSanitize(dataToSanitize: object | string, rules: SanitizerConfig): object | string {
|
||||
/**
|
||||
* BlockData It may contain 3 types:
|
||||
* - Array
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"target": "es2017",
|
||||
"declaration": false,
|
||||
"moduleResolution": "node", // This resolution strategy attempts to mimic the Node.js module resolution mechanism at runtime
|
||||
"lib": ["dom", "es2017", "es2018"],
|
||||
"lib": ["dom", "es2017", "es2018", "ES2019"],
|
||||
|
||||
// allows to import .json files for i18n
|
||||
"resolveJsonModule": true,
|
||||
|
|
|
|||
1
types/data-formats/index.d.ts
vendored
1
types/data-formats/index.d.ts
vendored
|
|
@ -1,2 +1,3 @@
|
|||
export * from './block-data';
|
||||
export * from './inline-fragments';
|
||||
export * from './output-data';
|
||||
|
|
|
|||
9
types/data-formats/inline-fragments.d.ts
vendored
Normal file
9
types/data-formats/inline-fragments.d.ts
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
export interface InlineFragment {
|
||||
range: [number, number];
|
||||
tool?: string;
|
||||
element: string;
|
||||
attributes?: Record<string, string>;
|
||||
}
|
||||
|
||||
export type InlineFragmentsDict = {[key: string]: InlineFragment[] | InlineFragmentsDict | InlineFragmentsDict[]};
|
||||
|
||||
3
types/data-formats/output-data.d.ts
vendored
3
types/data-formats/output-data.d.ts
vendored
|
|
@ -1,5 +1,6 @@
|
|||
import {BlockToolData} from '../tools';
|
||||
import {BlockTuneData} from '../block-tunes/block-tune-data';
|
||||
import {InlineFragmentsDict} from './inline-fragments';
|
||||
|
||||
/**
|
||||
* Output of one Tool
|
||||
|
|
@ -25,6 +26,8 @@ export interface OutputBlockData<Type extends string = string, Data extends obje
|
|||
* Block Tunes data
|
||||
*/
|
||||
tunes?: {[name: string]: BlockTuneData};
|
||||
|
||||
fragments?: InlineFragmentsDict;
|
||||
}
|
||||
|
||||
export interface OutputData {
|
||||
|
|
|
|||
|
|
@ -8944,7 +8944,12 @@ typedarray@^0.0.6:
|
|||
version "0.0.6"
|
||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||
|
||||
typescript@3.8.3, typescript@^3.7.3:
|
||||
typescript@4.4.3:
|
||||
version "4.4.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324"
|
||||
integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==
|
||||
|
||||
typescript@^3.7.3:
|
||||
version "3.8.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue