MCPcopy Create free account
hub / github.com/postlight/parser / selectHtml

Function selectHtml

src/extractors/root-extractor.js:97–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

95 }
96
97 function selectHtml() {
98 // If the selector type requests html as its return type
99 // transform and clean the element with provided selectors
100 let $content;
101
102 // If matching selector is an array, we're considering this a
103 // multi-match selection, which allows the parser to choose several
104 // selectors to include in the result. Note that all selectors in the
105 // array must match in order for this selector to trigger
106 if (Array.isArray(matchingSelector)) {
107 $content = $(matchingSelector.join(','));
108 const $wrapper = $('<div></div>');
109 $content.each((_, element) => {
110 $wrapper.append(element);
111 });
112
113 $content = $wrapper;
114 } else {
115 $content = $(matchingSelector);
116 }
117
118 // Wrap in div so transformation can take place on root element
119 $content.wrap($('<div></div>'));
120 $content = $content.parent();
121 $content = transformAndClean($content);
122 if (Cleaners[type]) {
123 Cleaners[type]($content, { ...opts, defaultCleaner });
124 }
125
126 if (allowMultiple) {
127 return $content
128 .children()
129 .toArray()
130 .map(el => $.html($(el)));
131 }
132
133 return $.html($content);
134 }
135
136 if (extractHtml) {
137 return selectHtml(matchingSelector);

Callers 1

selectFunction · 0.85

Calls 2

$Function · 0.85
transformAndCleanFunction · 0.85

Tested by

no test coverage detected