Skip to content

A web-based Markdown Editor with real-time preview, built with pure HTML, CSS and JavaScript. | 一個純 HTML、CSS 和 JavaScript 打造、且具有即時預覽功能的網頁 Markdown 編輯器。

License

pardnchiu/markdown-editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Markdown Editor

Feature

  • Provides separate editor and viewer modules for independent use.
  • Achieves real-time preview when the editor and viewer are used together.
  • Built using HTML, CSS / Sass and JavaScript.
  • Rendered using PDExtension-js.
  • Use Font Awesome 6 icons
  • Use code-prettify for code highlighting.
  • Preview available Here.

Creator

Pardn Chiu 邱敬幃

License

This source code project is licensed under the GPL-3.0 license.

How to use?

<script src="PDExtension.min.js" copyright="Pardn Ltd"></script>
<script src="PDMDEditor.min.js" copyright="Pardn Ltd"></script>
const editor = new MDEditor({
    id: "md-editor",
    style: {
        backgroundColor: "#0000ff1a", 
        color: "#0000ff", 
        placeholder: "Type here ...",
        placeholderColor: "#bfbfbf",
        showRow: 1
    }
});
const viewer = new MDViewer({ 
    id: "md-preview",
    pre: "" /* Default content. Displayed when the editor is empty. */
});

/* Add elements to the view. */
{DOM}.appendChild(editor.body);
{DOM}.appendChild(viewer.body);

/* Set the target viewer for the editor preview. */
editor.viewer = viewer; 

/* Initialize the editor and viewer. */
editor.init();
viewer.init();

MDEditor

interface MDEditor {
    // Initialize the editor.
    init: (pre: string) => void;
    // Add heading.
    addHeading: (num: number) => void;
    // Add bold.
    addBold: () => void;
    // Add italic.
    addItalic: () => void;
    // Add strikethrough.
    addStrikethrough: () => void;
    // Add underline.
    addUnderline: () => void;
    // Add marker.
    addMarker: () => void;
    // Add blockquote.
    addBlockquote: () => void;
    // Add unordered list.
    addUl: () => void;
    // Add ordered list.
    addOl: () => void;
    // Add code block.
    addCode: () => void;
    // Add hyperlink.
    addLink: (title: string, href: string) => void;
    // Add image.
    addImage: (src: string, alt: string, title: string) => void;
    // Clear editor content.
    clear: () => void;
    // Output as Markdown file.
    downloadMd: () => void;
    // Output as HTML file.
    downloadHtml: () => void;
    // Open .md file.
    openfile: (file) => void;
};

Example


©️ 2023 Pardn Chiu 邱敬幃

About

A web-based Markdown Editor with real-time preview, built with pure HTML, CSS and JavaScript. | 一個純 HTML、CSS 和 JavaScript 打造、且具有即時預覽功能的網頁 Markdown 編輯器。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages