-
Notifications
You must be signed in to change notification settings - Fork 953
Expand file tree
/
Copy pathgetFieldsToMark.js
More file actions
29 lines (27 loc) · 931 Bytes
/
getFieldsToMark.js
File metadata and controls
29 lines (27 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { flatten, isUndefined, uniq } from "lodash-es";
import { getSubheadings } from "./getSubheadings";
/**
* Gets the part of the html that we want to apply the marking to.
*
* @param {array} marks The array of mark objects.
* @param {string} html The html of the page where we want to apply the marking to.
*
* @returns {{selectedHTML: *[], fieldsToMark: *}} The selected part of the html we want to apply the marking tp.
*/
export function getFieldsToMark( marks, html ) {
const fieldsToMark = uniq( flatten( marks.map( mark => {
if ( ! isUndefined( mark.getFieldsToMark() ) ) {
return mark.getFieldsToMark();
}
} ) ) );
const selectedHTML = [];
fieldsToMark.forEach( field => {
if ( field === "heading" ) {
const subheadings = getSubheadings( html );
subheadings.forEach( subheading => {
selectedHTML.push( subheading[ 0 ] );
} );
}
} );
return { fieldsToMark, selectedHTML };
}