HtmlToMarkdown Class

Converts a web page at a given URL or a HTML string to Markdown. The headings, paragraphs, lists, tables, links, images, quotes and code of the HTML document are written with the Markdown syntax. The resulting Markdown text can be returned as a string or written to a file. The HTML to Markdown conversion requires the same runtime as the HTML to PDF conversion

Definition

Namespace: HiQPdf.Next
Assembly: HiQPdf.Next (in HiQPdf.Next.dll) Version: 19.1.0
C#
public class HtmlToMarkdown
Inheritance
Object    HtmlToMarkdown

Constructors

HtmlToMarkdown Creates a HTML to Markdown converter object with default options

Properties

AfterLoadJavaScript A JavaScript code to execute immediately after the page was loaded. It can be used to automatically click buttons or for other operations before conversion. By default this property is null
AllowInsecureContent Allows loading insecure HTTP content in secure HTTPS pages. The default value is false
Authentication The object exposed by this propery encapsulates a username and a password that can be used to access web pages requiring HTTP authentication
BlockedHosts A list of hosts the converter is not allowed to access when loading the page and its resources. An entry also blocks the subdomains of the host. Hosts are compared by name, so blocking an IP address does not block the host names that resolve to it
BrowserHeight The browser window height in pixels. The default height is 2048 pixels
BrowserWidth The browser window width in pixels. A responsive HTML document shows the content it has for this width. The default width is 1024 pixels
ConvertedElementsSelector Gets or sets the CSS selector used to identify the elements to include in the Markdown output. If this is not set or matches no elements, the entire HTML document will be converted
DisableWebSecurity Disables web security features such as CORS and same-origin policy. The default value is false
EnableElevatedRendering Enables the HTML renderer to inherit the elevated privileges of the application using the library when the application is running elevated on Windows. The default value is true
EnableSiteIsolation Enables site isolation, which renders the frames of a page that come from different sites in separate processes. The default value is false
EnableSoftwareGpuRendering When set to true, hardware GPU rendering is disabled and software rendering is used. When set to false, hardware GPU rendering is allowed and is further controlled by GpuRenderingEnabled and GpuCompositingEnabled. The default value is false
EncodeHttpPostFields When true (default), the converter applies application/x-www-form-urlencoded encoding to the names and values in the HttpPostFields collection when building the POST request body. Set to false only if the names and values are already form-urlencoded
ExcludedElementsSelector Gets or sets the CSS selector used to identify elements that should be excluded from the Markdown output
GpuCompositingEnabled A flag indicating if hardware GPU compositing is enabled in the HTML to Markdown converter. This property has effect only when EnableSoftwareGpuRendering is false. The default value is false
GpuRenderingEnabled A flag indicating if hardware GPU rendering is enabled in the HTML to Markdown converter. This property has effect only when EnableSoftwareGpuRendering is false. The default value is false
HtmlLoadedTimeout The maximum time in seconds to wait for HTML document to be loaded. The default value is 120 seconds. An exception is thrown if the HTML document cannot be loaded in HtmlLoadedTimeout seconds
HtmlLoaderFilePath Sets the full path of the HTML loader file
HttpCookies A collection of HTTP cookies to be used when accessing a web page in HTML to Markdown converter. Each entry must contain a valid cookie name and a RFC 6265-encoded value
HttpHeaders A collection of the HTTP headers to be used when accessing a web page in HTML to Markdown converter. Each entry must contain a valid HTTP header name and a printable ASCII value
HttpPostFields A collection of HTTP POST fields to be used when accessing a web page in HTML to Markdown converter. Each entry contains a parameter key and value. By default the converter form-urlencodes the keys and values when building the POST body; see EncodeHttpPostFields if the values are already encoded
IgnoreCertificateErrors Ignores certificate validation errors such as expired, self-signed or invalid certificates. The default value is false
ImageMode Gets or sets how the images of the HTML document are written in Markdown. The default value is Link
IncludeLinks A flag indicating if the links of the HTML document are written as Markdown links. When false only the text of the links is written. The default value is true
LazyImagesLoadMode The lazy content loading mode used by the HTML to Markdown converter. This property has effect only if LoadLazyImages is also true. The default mode is Browser
LoadLazyImages A flag indicating if the content loaded only when it becomes visible, like the lazy images, is loaded before the conversion. The default value is true
LocalFilesEnabled This property controls if the converter can convert local file. The default value is true
LocalhostEnabled This property controls if the converter can convert URLs from localhost. The default value is true
MaxBrowserHeight Gets or sets the maximum browser height in pixels used to load the lazy content. Value 0 means unlimited. The default value is 32000 pixels
MaxJsRedirects Gets or sets the maximum number of JavaScript-initiated redirects to follow in the main frame after the initial page load and before starting the conversion. Set this value to 0 to disable following JavaScript redirects. The default value is 10
MediaType Controls the media type for which to render the HTML document. The default value is null and the rendering will be for 'screen' media
Proxy The network proxy used to load the HTML page and its resources. By default no proxy is set and the network settings of the system are used
RepeatHttpHeaders This property controls if the headers defined by the HttpHeaders property are also used when accessing the resources referenced by the web page, not only when accessing the web page. The default value is false
RunJavaScript Controls if the JavaScript in the HTML document is executed. The default value of this property is true and the JavaScript is executed
TriggerMode The method of triggering the conversion
UncPathEnabled This property controls if the converter can convert files from local network. The default value is true
WaitAfterLoadJavaScript Controls if converter should wait the script from AfterLoadJavaScript to finish execution before continuing conversion. By default this property is false
WaitBeforeConvert An additional time in seconds to wait before starting the conversion to allow more time to JavaScript to update the web page. The default value is 0
WaitForSelector Gets or sets the CSS selector of an element to wait for before starting the conversion. The conversion starts when the HTML document contains an element matching the selector and ends with a navigation timeout error if no such element appears. By default this property is null
WriteHtmlToFileBeforeConvert When true, the HTML string is first written to a temporary file before conversion. When false, the HTML string is passed directly to the converter without file system involvement. The default value is false

Methods

ConvertHtmlToFile Converts a HTML string to Markdown using a base URL to resolve external resources and writes the Markdown text into a file encoded as UTF-8. A new instance of HtmlToMarkdown must be created for each call to this method
ConvertHtmlToFileAsync Asynchronously converts a HTML string to Markdown using a base URL to resolve external resources and writes the Markdown text into a file encoded as UTF-8. A new instance of HtmlToMarkdown must be created for each call to this method
ConvertHtmlToMarkdown Converts a HTML string to Markdown using a base URL to resolve external resources and returns the Markdown text. A new instance of HtmlToMarkdown must be created for each call to this method
ConvertHtmlToMarkdownAsync Asynchronously converts a HTML string to Markdown using a base URL to resolve external resources and returns the Markdown text. A new instance of HtmlToMarkdown must be created for each call to this method
ConvertUrlToFile Converts an URL to Markdown and writes the Markdown text into a file encoded as UTF-8. A new instance of HtmlToMarkdown must be created for each call to this method
ConvertUrlToFileAsync Asynchronously converts an URL to Markdown and writes the Markdown text into a file encoded as UTF-8. A new instance of HtmlToMarkdown must be created for each call to this method
ConvertUrlToMarkdown Converts an URL to Markdown and returns the Markdown text. A new instance of HtmlToMarkdown must be created for each call to this method
ConvertUrlToMarkdownAsync Asynchronously converts an URL to Markdown and returns the Markdown text. A new instance of HtmlToMarkdown must be created for each call to this method
Equals
(Inherited from Object)
Finalize
(Inherited from Object)
GetHashCode
(Inherited from Object)
GetType
(Inherited from Object)
MemberwiseClone
(Inherited from Object)
ToString
(Inherited from Object)

See Also