Benjamin Kenwright
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Simple Mardown (**sweety and simple**) to HTML using **RegEx** Patterns. Combining multiple regular expression patterns that focus on different areas of the markdown language (e.g., code blocks, bold, alert boxes). :::danger Just to emphasis this is a **simple markdown** project demo. Using basic regular expressions to match markdown patterns in a document. A more robust solution would be to implement your own token parser (essentially a complete compiler/syntax analyser). This way you'd go token by token and toggle global flags and take appropriate action. ::: A nice aspect of the simple markdown solution, is each regular expression can be tested and enabled/disabled seperately. In a few special cases, for example **code blocks**, the region of the text is removed so other expressions don't cause interference. Different markdown commands have priority (e.g., bold text) can still be set inside an alert box region (but not inside a HTML or code block). ## Alert Boxes The alert box is a juicy little trick to emphasis key points in color (such as warnings or information). The syntax for alert boxes is simply a **triple colon** followed by the alert box type. For our example, we'll have 4 alert box types (success, info, warning and danger). ``` :::success Yes - it works!! ::: :::info This is a message - useulf ::: :::warning Watch out - a warning!! ::: :::danger Oh No! Danger Will Robinson Danger Danger! ::: ``` This is what the alert boxes might look like (simple 'div' tag with color style information): :::success Yes - it works!! ::: :::info This is a message - useulf ::: :::warning Watch out - a warning!! ::: :::danger Oh No! Danger Will Robinson Danger Danger! ::: This is the regular expression to identify the alert box region. The pattern uses groups to identify both the content and the alert box type. :::info **RegEx Alert Boxes** ``` /(\n|^):::(.*?)(\n)((.|\n)*?)\n:::(\n|$)/ ``` ::: The regular expression has **multiple groups** to extract both the content and the alert box type (success/info). The success/info name is used to set the style information. The groups are mapped to a DIV: ``` <div class="$2">$4</div> ``` * $2 - second group item (e.g., success/info/..) * $4 - forth group item (e.g., body of the alert box) Example of the CSS color scheme, the CSS class name is from the alert box **name** (e.g., success/info). If there was an issue with the name (conflict), we could append something (like 'alert-') to the front so it has a unique class name. ``` <style> .info { background-color:rgba(0, 0, 255,0.2); padding:20px; } .success { background-color:rgba(0, 255,0, 0.2); padding:20px; } .warning { background-color:rgba(255,0, 255,0.2); padding:20px; } .danger { background-color:rgba(255,0, 0, 0.2); padding:20px; } </style> ``` You could further enhance the styles, add rounded corners or different shapes/patterns for the boxes (background graphics). ## ToDo List The checkbox syntax is a quick way to visualize done and **not** done activities. Of course, you could change the HTML design to be a graphic (e.g., fancy tick icon or cross). You could even enhance it further by making the nested checkbox elements have different styles? ``` - [ ] ToDos - [x] Buy some salad - [ ] Brush teeth - [x] Drink some water - [ ] Have nap - [x] Feed cat ``` - [ ] ToDos - [x] Buy some salad - [ ] Brush teeth - [x] Drink some water - [ ] Have nap - [x] Feed cat Note, this is what the HTML for checkboxes looks like: ``` <input type="checkbox"> <input type="checkbox" checked> ``` The default HTML checkbox style looks like: <input type="checkbox"> or <input type="checkbox" checked> :::info **RegEx for Checkboxes (with Nesting)** ``` /(\n|^)((| )*?)- \[( |x)\] (.*?)(?=\n|$)/ ``` ::: ## Blockquote Tags ``` > Using the arrow to emphasis block quotations. ``` > Using the arrow to emphasis block quotations. Since we're using regular expressions - each line should have an arrow for it to be included in the block quote. The markdown specification says the block should continue until a double line is hit, however, we'll require each line with an arrow to be a block (helps with the next bit on **nesting**). **Nested** This is so we can have **multiple** arrows to have **nested** blocks. Blocks within blocks. The **tricky** part is the syntax can be both arrows with and without a space between them (i.e., '>>>' and '> > >'). ``` > Blockquotes can also be nested... >> ...by using additional greater-than signs right next to each other... > > > ...or with spaces between arrows. ``` > Blockquotes can also be nested... >> ...by using additional greater-than signs right next to each other... > > > ...or with spaces between arrows. :::info **RegEx for Blockquote (with Nesting)** ``` /(\n|^)((>|> )*?) (.*?)(?=\n|$)/ ``` ::: ## Emphasis Standard ways to make test stand out - from bold and italic to the more fancy deleted (line through) options. ``` **This is bold text** *This is italic text* ~~Deleted text~~ ``` **This is bold text** *This is italic text* ~~Deleted text~~ :::info **RegEx for Bold** ``` /[*][*](.*?)[*][*]/ ``` ::: :::info **RegEx for Italic** ``` /[*](.*?)[*]/ ``` ::: :::info **RegEx for Deleted** ``` /[~][~](.*?)[~][~]/ ``` ::: ## Code Blocks Code blocks are defined two triple backticks (\`\`\`) - one for the start and one for the end. When you're in a block of code, you don't want anthing to interfere. For example, you might want a code block with markdown or html. To resove this with RegEx, we prioratise this, so at the start, we identify the code blocks and **remove** them from the text (stored them in an array). After we've processed and modified the markdown in the document we re-insert the code blocks (safe and unmodified) with the appropriate wrappings. :::danger In HTML, you can use the **pre** tag to disable formatting (sort of a raw display). This works great in most cases, however, it breaks when you're displaying **HTML**. As the HTML tags are still parsed. There are lots of different ways around this, but a simple hacky way is to use a **textarea** block instead of a **pre**. ::: **1.** Match and Extract (**Store**) all Code Blocks** :::info RegEx Match All Code Blocks ``` "/```(.+)```(?=\n)/ ``` ::: **2.** **Replace** all Code Blocks :::info RegEx Replace All Code Blocks with **[MCODE]** ``` "/```(.+)```(?=\n)/ ``` ::: **3.** Perform any **markdown processing** and modifications on the text **4.** End **Restore** all [MCODE] placeholders with Stored Code :::info ``` /\MCODE\]/ ``` ::: **Hacking Textarea Resize** A small problem with the **textarea** tag is that it doesn't automatically resize to the **content**. So if you want it to have the same **height** as the text you have to do a little extra work. A small **hack** here was to piggy back on the **img** tag. Which tries to load an image, when it fails, it calls the error callback - which we use to check the neighboring textarea and resize it to the height of the content. HTML/JS Example: ``` <div> <textarea style="overflow:hidden; width:100%; border:0; color:black; background-color:rgba(100,100,250,0.1)"> cats dogs and chickens </ textarea> <img src onerror="this.parentNode.children[0].style.height=this.parentNode.children[0].scrollHeight+'px'" > </div> ``` Link to test it out on Notebook [<a href='https://notebook.xbdev.net/index.php?page=textareaauto&'>LINK</a>]

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully