Simanalix343

markdownToHTML.html

Oct 22nd, 2020 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.79 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  5.     <meta name="" content="">
  6.     <title>Markdown to HTML</title>
  7.     <style>
  8. *{padding:0px;margin:0px;box-sizing:border-box;}
  9. div{
  10.   padding:1px;
  11.   border:2px solid #dddddd;
  12.   margin:1px;
  13. }
  14. .li-before{
  15.   margin:0px;
  16.   padding:0px;
  17.   border:none;
  18.   display:inline-block;
  19.   color:transparent;
  20.   width:14px;
  21.   height:14px;
  22.   background-image:conic-gradient(#000000 0deg,#222222 90deg,#777777 180deg,#222222 270deg,#000000 360deg);
  23.   border-radius:7px;
  24.   margin-left:4px;
  25.   margin-right:4px;
  26. }
  27. .superscript{
  28.   margin:0px;
  29.   padding:0px;
  30.   border:none;
  31.   font-size:10px;
  32.   display:inline;
  33.   position:relative;
  34.   bottom:10px;
  35. }
  36. .other{
  37.   margin:0px;
  38.   padding:0px;
  39.   border:none;
  40. }
  41.     </style>
  42.   </head>
  43.   <body>
  44.    
  45.    
  46.     <script>
  47.  
  48.  
  49. var a=[
  50.   />/g,
  51.   /</g,
  52.  /\\\\/g,
  53.  /\\\[/g,
  54.  /\\\]/g,
  55.  /\\\*/g,
  56.  /\\\|/g,
  57.  /\\\//g,
  58.  /\\-/g,
  59.  /\\&/g,
  60.  /\\\^/g,
  61.  /\[(?<text>[^\]]+)\]\((http(?<safe>s?):\/\/)?(www\.)?(?<domain>(\w+\.)+(\w+))\)/g,
  62.   /(?<text>(http(?<safe>s?):\/\/)?(www\.)?(?<domain>(\w+\.)+(\w+)))/g,
  63.   /\*\*\*(?<text>[^*]+)\*\*\*/g,
  64.   /\*\*(?<text>[^*]+)\*\*/g,
  65.   /\*(?<text>[^*]+)\*/g,
  66.   /^\s*(?<li>[+\-*]+ +(?<text>[^\n\r\s][^\n\r]*))/gm,
  67.   /(?<text>((<li>)+((?!<\/li>).)+(<\/li>)+[\s\n\r]*)+)/g,
  68.   /(?<=<\/li>)[\s\n\r]+(?=<\/ul>)/g,
  69.   /(?<=<ul>)[\s\n\r]+(?=<li>)/g,
  70.   /\n\n+/g,
  71.   /\s\s+\n/g,
  72.   /\^\((?<text>[^\n\r)]+)\)/g,
  73.   /\^(?<text>[^\s\n\r)]+)/g
  74. ]
  75.  
  76. var c=[
  77.   "&gt;",
  78.   "&lt;",
  79.   "&#92",
  80.  "&#91",
  81.  "&#93",
  82.  "&#42",
  83.  "&#124",
  84.  "&#47",
  85.  "&#45",
  86.  "&#38",
  87.  "&#94",
  88.  "<a href=\"http$<safe>://www.$<domain>\">$<text></a>",
  89.  "<a href=\"http$<safe>://www.$<domain>\">$<text></a>",
  90.  "<b><i>$<text></i></b>",
  91.  "<b>$<text></b>",
  92.  "<i>$<text></i>",
  93.  "<li><div class=\"li-before\"></div>$<text></li>",
  94.  "<ul>$<text></ul>",
  95.  "",
  96.  "",
  97.  "</div><div>",
  98.  "<br>",
  99.  "<div class=\"superscript\">$<text></div>",
  100.  "<div class=\"superscript\">$<text></div>"
  101. ]
  102.  
  103. var b=`I like this [search engine](https://www.google.com), and this [video player](youtube.com).
  104.  
  105. This <i> should be fine.
  106.  
  107. My name here on Reddit ^(not this site) is Simanelix and I moderate on r/idlegamemaker.
  108.  
  109. - this
  110. - is a simple
  111. - and also unordered
  112. - list of things
  113.  
  114. I wnat to madk a *really* cool IGM tool, and a simple but **useful** markdown transformer. This text *start out in italics, but ****then goes bold, *****later exits italics, **and eventually returns to normal.
  115.  
  116. I hope ***you*** have a great day.`;
  117.  
  118. function markdownToHTML(){
  119.   for(let i in a){
  120.     b=b.replace(a[i],c[i]);
  121.   }
  122.   document.body.innerHTML="<div>"+b+"</div>";
  123. }
  124. markdownToHTML();
  125.  
  126. /*
  127. .replace(/>/g,"&gt;").replace(/</g,"&lt;")
  128. */
  129.    </script>
  130.   </body>
  131. </html>
Add Comment
Please, Sign In to add comment