@@ -2,7 +2,6 @@ import { NodeHtmlMarkdownOptions } from './options';
22import { ElementNode , HtmlNode } from './nodes' ;
33import { nodeHtmlParserConfig } from './config' ;
44
5-
65/* ****************************************************************************************************************** */
76// region: String Utils
87/* ****************************************************************************************************************** */
@@ -123,6 +122,9 @@ export const truthyStr = (v: any, value?: string): string => v ? ((value !== und
123122/* ****************************************************************************************************************** */
124123// region: Parser
125124/* ****************************************************************************************************************** */
125+ // For esbuild removing code
126+ declare global { const __IS_BROWSER__ : boolean }
127+
126128
127129function tryParseWithNativeDom ( html : string ) : ElementNode | undefined {
128130 try {
@@ -169,24 +171,25 @@ const getNodeHtmlParser = () => {
169171export function parseHTML ( html : string , options : NodeHtmlMarkdownOptions ) : ElementNode {
170172 let nodeHtmlParse : ReturnType < typeof getNodeHtmlParser > ;
171173
172- /* If specified, try to parse with native engine, fallback to node-html-parser */
173174 perfStart ( 'parse' ) ;
174175 let el : ElementNode | undefined ;
175- if ( options . preferNativeParser ) {
176+ /* If specified, try to parse with native engine, fallback to node-html-parser */
177+ if ( __IS_BROWSER__ || options . preferNativeParser ) {
176178 try {
177179 el = tryParseWithNativeDom ( html ) ;
178180 }
179181 catch ( e ) {
182+ if ( __IS_BROWSER__ ) throw e ;
180183 nodeHtmlParse = getNodeHtmlParser ( ) ;
181184 if ( nodeHtmlParse ) console . warn ( 'Native DOM parser encountered an error during parse' , e ) ;
182185 else throw e ;
183186 }
184187 } else nodeHtmlParse = getNodeHtmlParser ( ) ;
185188
186- if ( ! el ) el = nodeHtmlParse ! ( html , nodeHtmlParserConfig ) ;
189+ if ( ! __IS_BROWSER__ && ! el ) el = nodeHtmlParse ! ( html , nodeHtmlParserConfig ) ;
187190 perfStop ( 'parse' ) ;
188191
189- return el ;
192+ return el ! ;
190193}
191194
192195// endregion
0 commit comments