mirror of
				https://github.com/notion-enhancer/notion-enhancer.git
				synced 2025-11-04 16:18:08 +11:00 
			
		
		
		
	improve markdown regexes
This commit is contained in:
		
							parent
							
								
									158ce182df
								
							
						
					
					
						commit
						6dacae46b5
					
				@ -83,6 +83,9 @@ code {
 | 
				
			|||||||
u {
 | 
					u {
 | 
				
			||||||
  text-decoration: underline;
 | 
					  text-decoration: underline;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					s {
 | 
				
			||||||
 | 
					  text-decoration: line-through;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* titlebar */
 | 
					/* titlebar */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -188,22 +191,29 @@ u {
 | 
				
			|||||||
  margin: 0.3em 0 0.4em 0;
 | 
					  margin: 0.3em 0 0.4em 0;
 | 
				
			||||||
  font-size: 0.9em;
 | 
					  font-size: 0.9em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#modules section .desc p {
 | 
				
			||||||
 | 
					  margin: 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#modules section .desc blockquote {
 | 
				
			||||||
 | 
					  margin: 0.3em 0;
 | 
				
			||||||
 | 
					  border-left: 0.3em solid var(--theme_local--table-border);
 | 
				
			||||||
 | 
					  padding-left: 0.7em;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#modules section .desc a {
 | 
					#modules section .desc a {
 | 
				
			||||||
  color: currentColor;
 | 
					  color: currentColor;
 | 
				
			||||||
  text-decoration: underline dotted;
 | 
					  text-decoration: underline dotted;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#modules section .desc s {
 | 
					
 | 
				
			||||||
  text-decoration: line-through;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#modules section .desc img {
 | 
					#modules section .desc img {
 | 
				
			||||||
  width: 100%;
 | 
					  width: 100%;
 | 
				
			||||||
  max-width: 20em;
 | 
					  max-width: 20em;
 | 
				
			||||||
  margin: 0.5em 0;
 | 
					  margin: 0.5em 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#modules section .desc img:first-child {
 | 
					#modules section .desc :first-child img:first-child {
 | 
				
			||||||
  margin-top: 0;
 | 
					  margin-top: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#modules section .desc img:last-child {
 | 
					#modules section .desc :last-child img:last-child {
 | 
				
			||||||
  margin-bottom: 0;
 | 
					  margin-bottom: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -110,36 +110,43 @@ window['__start'] = async () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // mod options
 | 
					  // mod options
 | 
				
			||||||
  function markdown(string) {
 | 
					  function markdown(string) {
 | 
				
			||||||
    return string
 | 
					    const parsed = string
 | 
				
			||||||
      .split('\n')
 | 
					      .split('\n')
 | 
				
			||||||
      .map((line) =>
 | 
					      .map((line) =>
 | 
				
			||||||
        line
 | 
					        line
 | 
				
			||||||
          // todo: stop e.g. whole chunk of ~~thin~~g~~ being selected
 | 
					          // todo: stop e.g. whole chunk of ~~thin~~g~~ being selected
 | 
				
			||||||
          .trim()
 | 
					          .trim()
 | 
				
			||||||
 | 
					          .replace(/\s+/g, ' ')
 | 
				
			||||||
 | 
					          // > quote
 | 
				
			||||||
 | 
					          .replace(/^>\s+(.+)$/g, '<blockquote>$1</blockquote>')
 | 
				
			||||||
          // ~~strikethrough~~
 | 
					          // ~~strikethrough~~
 | 
				
			||||||
          .replace(/([^\\])?~~([^\n]*[^\\])~~/g, '$1<s>$2</s>')
 | 
					          .replace(/([^\\])?~~((?:(?!~~).)*[^\\])~~/g, '$1<s>$2</s>')
 | 
				
			||||||
          // __underline__
 | 
					          // __underline__
 | 
				
			||||||
          .replace(/([^\\])?__([^\n]*[^\\])__/g, '$1<u>$2</u>')
 | 
					          .replace(/([^\\])?__((?:(?!__).)*[^\\])__/g, '$1<u>$2</u>')
 | 
				
			||||||
          // **bold**
 | 
					          // **bold**
 | 
				
			||||||
          .replace(/([^\\])?\*\*([^\n]*[^\\])\*\*/g, '$1<b>$2</b>')
 | 
					          .replace(/([^\\])?\*\*((?:(?!\*\*).)*[^\\])\*\*/g, '$1<b>$2</b>')
 | 
				
			||||||
          // *italic*
 | 
					          // *italic*
 | 
				
			||||||
          .replace(/([^\\])?\*([^\n]*[^\\])\*/g, '$1<i>$2</i>')
 | 
					          .replace(/([^\\])?\*([^*]*[^\\*])\*/g, '$1<i>$2</i>')
 | 
				
			||||||
          // _italic_
 | 
					          // _italic_
 | 
				
			||||||
          .replace(/([^\\])?_([^\n]*[^\\])_/g, '$1<i>$2</i>')
 | 
					          .replace(/([^\\])?_([^_]*[^\\_])_/g, '$1<i>$2</i>')
 | 
				
			||||||
          // `code`
 | 
					          // `code`
 | 
				
			||||||
          .replace(/([^\\])?`([^\n]*[^\\])`/g, '$1<code>$2</code>')
 | 
					          .replace(/([^\\])?`([^`]*[^\\`])`/g, '$1<code>$2</code>')
 | 
				
			||||||
          // 
 | 
					          // 
 | 
				
			||||||
          .replace(
 | 
					          .replace(
 | 
				
			||||||
            /([^\\])?\!\[([^\n]*[^\\]?)\]\(([^\n]*[^\\])\)/g,
 | 
					            /([^\\])?\!\[([^\]]*[^\\\]]?)\]\(([^)]*[^\\)])\)/g,
 | 
				
			||||||
            '$1<img alt="" src="$3">$2</a>'
 | 
					            '$1<img alt="" src="$3">$2</img>'
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
          // [link](destination)
 | 
					          // [link](destination)
 | 
				
			||||||
          .replace(
 | 
					          .replace(
 | 
				
			||||||
            /([^\\])?\[([^\n]*[^\\])\]\(([^\n]*[^\\])\)/g,
 | 
					            /([^\\])?\[([^\]]*[^\\\]]?)\]\(([^)]*[^\\)])\)/g,
 | 
				
			||||||
            '$1<a href="$3">$2</a>'
 | 
					            '$1<a href="$3">$2</a>'
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      .join('<br>');
 | 
					      .map((line) =>
 | 
				
			||||||
 | 
					        line.startsWith('<blockquote>') ? line : `<p>${line}</p>`
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      .join('');
 | 
				
			||||||
 | 
					    return parsed;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  const $modules = document.querySelector('#modules');
 | 
					  const $modules = document.querySelector('#modules');
 | 
				
			||||||
  for (let mod of modules.loaded.sort((a, b) => {
 | 
					  for (let mod of modules.loaded.sort((a, b) => {
 | 
				
			||||||
@ -176,7 +183,7 @@ window['__start'] = async () => {
 | 
				
			|||||||
        <p class="tags">${mod.tags
 | 
					        <p class="tags">${mod.tags
 | 
				
			||||||
          .map((tag) => (tag.startsWith('#') ? tag : `#${tag}`))
 | 
					          .map((tag) => (tag.startsWith('#') ? tag : `#${tag}`))
 | 
				
			||||||
          .join(' ')}</p>
 | 
					          .join(' ')}</p>
 | 
				
			||||||
        <p class="desc">${markdown(mod.desc)}</p>
 | 
					        <div class="desc">${markdown(mod.desc)}</div>
 | 
				
			||||||
        <p>
 | 
					        <p>
 | 
				
			||||||
          <a href="https://github.com/${mod.author}" class="author">
 | 
					          <a href="https://github.com/${mod.author}" class="author">
 | 
				
			||||||
            <img src="https://github.com/${mod.author}.png" />
 | 
					            <img src="https://github.com/${mod.author}.png" />
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ module.exports = {
 | 
				
			|||||||
  id: '0f0bf8b6-eae6-4273-b307-8fc43f2ee082',
 | 
					  id: '0f0bf8b6-eae6-4273-b307-8fc43f2ee082',
 | 
				
			||||||
  tags: ['core', 'extension'],
 | 
					  tags: ['core', 'extension'],
 | 
				
			||||||
  name: 'notion-enhancer core',
 | 
					  name: 'notion-enhancer core',
 | 
				
			||||||
  desc: `the **modloader** itself, _including_: the [CLI](https://github.com), the \`menu\`, and ~~enabling/disabling/insertion/updating of~~ mods.
 | 
					  desc: `> the **modloader** itself, _including_: the [CLI](https://github.com), the \`menu\`, and ~~enabling/disabling/insertion/updating of~~ mods.
 | 
				
			||||||
    `,
 | 
					    `,
 | 
				
			||||||
  version: require('../../package.json').version,
 | 
					  version: require('../../package.json').version,
 | 
				
			||||||
  author: 'dragonwocky',
 | 
					  author: 'dragonwocky',
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user