|
| 1 | +// https://github.com/gjtorikian/html-pipeline/blob/main/lib/html_pipeline/sanitization_filter.rb |
| 2 | +export const ALLOW_TAGS = new Set([ |
| 3 | + 'h1', |
| 4 | + 'h2', |
| 5 | + 'h3', |
| 6 | + 'h4', |
| 7 | + 'h5', |
| 8 | + 'h6', |
| 9 | + 'br', |
| 10 | + 'b', |
| 11 | + 'i', |
| 12 | + 'strong', |
| 13 | + 'em', |
| 14 | + 'a', |
| 15 | + 'pre', |
| 16 | + 'code', |
| 17 | + 'img', |
| 18 | + 'tt', |
| 19 | + 'div', |
| 20 | + 'ins', |
| 21 | + 'del', |
| 22 | + 'sup', |
| 23 | + 'sub', |
| 24 | + 'p', |
| 25 | + 'picture', |
| 26 | + 'ol', |
| 27 | + 'ul', |
| 28 | + 'table', |
| 29 | + 'thead', |
| 30 | + 'tbody', |
| 31 | + 'tfoot', |
| 32 | + 'blockquote', |
| 33 | + 'dl', |
| 34 | + 'dt', |
| 35 | + 'dd', |
| 36 | + 'kbd', |
| 37 | + 'q', |
| 38 | + 'samp', |
| 39 | + 'var', |
| 40 | + 'hr', |
| 41 | + 'ruby', |
| 42 | + 'rt', |
| 43 | + 'rp', |
| 44 | + 'li', |
| 45 | + 'tr', |
| 46 | + 'td', |
| 47 | + 'th', |
| 48 | + 's', |
| 49 | + 'strike', |
| 50 | + 'summary', |
| 51 | + 'details', |
| 52 | + 'caption', |
| 53 | + 'figure', |
| 54 | + 'figcaption', |
| 55 | + 'abbr', |
| 56 | + 'bdo', |
| 57 | + 'cite', |
| 58 | + 'dfn', |
| 59 | + 'mark', |
| 60 | + 'small', |
| 61 | + 'source', |
| 62 | + 'span', |
| 63 | + 'time', |
| 64 | + 'wbr', |
| 65 | + 'body', |
| 66 | + 'html', |
| 67 | + 'g-emoji', |
| 68 | + 'input', // [type=checkbox], for task list |
| 69 | +]); |
| 70 | + |
| 71 | +export const ALLOW_CLASS = new Set([ |
| 72 | + '.anchor', |
| 73 | + '.g-emoji', |
| 74 | + '.highlight', |
| 75 | + '.octicon', |
| 76 | + '.octicon-link', |
| 77 | + '.contains-task-list', |
| 78 | + '.task-list-item', |
| 79 | + '.task-list-item-checkbox', |
| 80 | + // For Markdown alerts. |
| 81 | + '.octicon-info', |
| 82 | + '.octicon-light-bulb', |
| 83 | + '.octicon-report', |
| 84 | + '.octicon-alert', |
| 85 | + '.octicon-stop', |
| 86 | + '.markdown-alert', |
| 87 | + '.markdown-alert-title', |
| 88 | + '.markdown-alert-note', |
| 89 | + '.markdown-alert-tip', |
| 90 | + '.markdown-alert-important', |
| 91 | + '.markdown-alert-warning', |
| 92 | + '.markdown-alert-caution', |
| 93 | + '.mr-2', |
| 94 | +]); |
| 95 | + |
| 96 | +const octicon = String.raw`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' version='1.1' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg>`; |
| 97 | + |
| 98 | +export const manuallyAddedStyle = ` |
| 99 | +.markdown-body .octicon { |
| 100 | + display: inline-block; |
| 101 | + fill: currentColor; |
| 102 | + vertical-align: text-bottom; |
| 103 | +} |
| 104 | +
|
| 105 | +.markdown-body h1:hover .anchor .octicon-link:before, |
| 106 | +.markdown-body h2:hover .anchor .octicon-link:before, |
| 107 | +.markdown-body h3:hover .anchor .octicon-link:before, |
| 108 | +.markdown-body h4:hover .anchor .octicon-link:before, |
| 109 | +.markdown-body h5:hover .anchor .octicon-link:before, |
| 110 | +.markdown-body h6:hover .anchor .octicon-link:before { |
| 111 | + width: 16px; |
| 112 | + height: 16px; |
| 113 | + content: ' '; |
| 114 | + display: inline-block; |
| 115 | + background-color: currentColor; |
| 116 | + -webkit-mask-image: url("data:image/svg+xml,${octicon}"); |
| 117 | + mask-image: url("data:image/svg+xml,${octicon}"); |
| 118 | +} |
| 119 | +`; |
0 commit comments