Class MarkdownDocument

Class that wraps the Active Markdown document used in the editor. [ComVisible] is important as we access this from JavaScript

System.Object
  MarkdownMonster.MarkdownDocument
public class MarkdownDocument : object, INotifyPropertyChanged

Class Members

MemberDescription

Constructor

BeforeDocumentRendered

Event that fires just before the document is rendered. It's passed the Markdown text before it is converted to HTML so you can intercept and modify the markdown before rendering.

Return back the final markdown.

DocumentRendered

Event that fires after the final HTML document has been created when merging with a preview template. The html contains the fully rendered HTML document before it is returned or written to file.

Parameters: * Rendered Html * Original Markdown

You return: * Updated (or unaltered) HTML

IsDirtyChanged

Event fired when the dirty changed of the document changes

MarkdownRendered

Event that fires after the raw markdown has been rendered to html. Note this will be an HTML fragment not an HTML document.

Parameters: * Rendered Html * Original Markdown

You return: * Updated (or unaltered) HTML

PropertyChanged

PREVIEW_HTML_FILENAME

PREVIEW_HTML_SOURCE_FILENAME

UNTITLED

AddExtraHeaders

Allows adding extra headers that are embedded into the HTML output file's HEAD section

public void AddExtraHeaders(string extraHeaderText)

AutoSaveAsync

Creates a backup file

public Task AutoSaveAsync(string filename)

CleanupBackupFile

Cleans up the backup file and removes the timer

public void CleanupBackupFile(string filename)

Close

Cleans up after the file is closed by deleting the HTML render file.

public void Close()

GetDocumentTitle

Tries to retrieve the title from the active document and returns the title text or as a kebab case filename. If title can't be resolved null is returned.

public string GetDocumentTitle(string markdownText,     bool asFilename)

GetFileEncoding

Retrieve the file encoding for a given file so we can capture and store the Encoding when writing the file back out after editing.

Default is Utf-8 (w/ BOM). If file without BOM is read it is assumed it's UTF-8.

public void GetFileEncoding(string filename)

GetPreviewWebRootPath

Sets the PreviewWebRootPath from content in the YAML of the document: webRootPath: c:\temp\post\Topic\

public string GetPreviewWebRootPath()

GetWebRootPathFromMarkerFiles

Retrieves a Web Root path that is used to resolving / and /~ in the Previewer so that related resources that site relative paths can be resolved.

public string GetWebRootPathFromMarkerFiles(string basePath)

GetWebRootRelativePath

Returns a WebRoot Relative and slash normalized path for a file based on the current document's base file. Paths are converted to forward slashes as embeddable links. If path is empty or untitled path is returned as is.

public string GetWebRootRelativePath(string path,     string basePath)

HasBackupFile

Checks to see whether there's a backup file present

public bool HasBackupFile()

HasFileChanged

Determines whether text has changed from original.

This method exists to explicitly check the dirty state which can be set from a number of sources.

public bool HasFileChanged(string currentText)

HasFileCrcChanged

Checks to see if the CRC has changed

public bool HasFileCrcChanged()

IsFileEncrypted

Determines whether the file on disk is encrypted

public bool IsFileEncrypted(string filename)

Load

Loads the markdown document into the CurrentText

public Task Load(string filename,     SecureString password,     Encoding encoding,     bool isAsync)

OnBeforeDocumentRendered

public void OnBeforeDocumentRendered(ref string markdown)

OnDocumentRendered

Fires after HTML has been generated from Markdown and has been merged into the template. At this point HTML contains a full HTML document.

You can also set additional HEAD content for the HTML header.

public void OnDocumentRendered(ref string html,     ref string markdown)

OnMarkdownRendered

Post processing of the the rendered markdown fragment that has been turned into html (before it has been merged into the document template).

public void OnMarkdownRendered(ref string html,     ref string markdown)

OnPropertyChanged

public virtual void OnPropertyChanged(string propertyName)

RenderHtml

Renders markdown of the current document text into raw HTML

public string RenderHtml(string markdown,     bool usePragmaLines,     bool noBanner)

RenderHtmlToFile

Renders markdown from the current document using the appropriate Theme Template and writing an output file. Options allow customization and can avoid writing out a file.

public Task RenderHtmlToFile(string markdown,     string filename,     string theme,     bool usePragmaLines,     bool noFileWrite,     bool removeBaseTag,     bool noBanner)

RenderHtmlWithTemplate

Renders HTML output with the active Template to a full HTML document as a string.

public Task RenderHtmlWithTemplate(string markdown,     string theme,     bool usePragmaLines,     bool removeBaseTag,     bool noBanner)

ResolveSyntaxFromFilename

Resolves syntax based on the filename extension. Untitled

public string ResolveSyntaxFromFilename(string filename)

Save

Saves the CurrentText into the specified filename

public bool Save(string filename,     bool noBackupFileCleanup,     SecureString password)

SaveAsync

Saves the CurrentText into the specified filename

public Task SaveAsync(string filename,     bool noBackupFileCleanup,     SecureString password)

public Task SaveAsync(string filename,     bool noBackupFileCleanup,     SecureString password,     bool isAsync)

SetHtmlRenderFilename

Allows you to explicitly override the render filename used for previewing. This allows addins to render out of custom folders when previewing since the previewer uses the HtmlRenderFilename.

This overrides the default location in the temp folder.

public void SetHtmlRenderFilename(string filename)

StripFrontMatter

Strips Front Matter from markdown and returns just the Markdown

public static string StripFrontMatter(string markdown)

ToString

public virtual string ToString()

UpdateCrc

Stores the CRC of the file as currently exists on disk

public void UpdateCrc(string filename)

WriteFile

Writes the file with a retry

public bool WriteFile(string filename,     string html)

WriteFileAsync

Writes the file with a retry

public Task WriteFileAsync(string filename,     string html)

AutoSaveBackup

Determines whether backups are automatically saved

Defaults to Configuration.AutoSaveBackups

AutoSaveDocument

Determines whether documents are automatically saved in the background as soon as changes are made and you stop typing for a second. This setting takes precendence over AutoSaveBackups.

Defaults to Configuration.AutoSaveDocuments

BackupFilename

Name of the auto save backup file

CurrentText

Holds the actively edited Markdown text

Dispatcher

Window dispatcher to ensure we're synchronizing in the right context always.

EditorSyntax

Encoding

Document encoding used when writing the document to disk. Default: UTF-8 without a BOM

ExtraHtmlHeaders

Extra HTML document headers that get get added to the document in the headsection of the HTML document.

FileCrc

Holds the disk file Crc of the document. This value is used to determine if the document on disk has changed when activating a document after having navigated off and when saving.

Filename

Name of the Markdown file. If this is a new file the file is named 'untitled'

FilenamePathWithIndicator

Returns a filename plus path and a change indicator Used when multiple tabs with the same file are open

FilenameWithIndicator

Returns the filename with a dirty indicator (*) if the document has changed

FilePath

Returns the path of the open document. Null for empty or Untitled documents.

HtmlRenderFilename

This is the filename used when rendering this document to HTML

IsActive

Determines whether the document is the active document

IsDirty

Determines whether the active document has changes that have not been saved yet

IsEncrypted

Determines whether the file is encrypted

IsUntitled

LastEditorLineNumber

Holds the last preview window browser scroll position so it can be restored when refreshing the preview window.

LastImageFolder

The last Image Folder used for this document

LastSaveTime

OriginalText

The original text of the document since the last save operation. Updated whenever a document is saved.

Password

Holds the username and password

PreviewWebRootPath

Path that maps / in the rendered document. If non-null this value is fixed up for special case translation in the HTML output.

Useful for fixing up root links when generating previews so the renderer can figure out a base path to render ~/ or / links from.

ProcessScripts

Internal property used to identify whether scripts are processed

Title

Tries to return the title from the active Markdown document by looking at:

1 - For # title line in the first 5 lines of text 2 - Camel Case File names 3 - Untitled - stays untitled.

Requirements

Namespace: MarkdownMonster
Assembly: markdownmonster.exe

© West Wind Technologies, 2016-2024 • Updated: 11/23/21
Comment or report problem with topic