mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 01:53:11 +08:00
Feat: add highlight menu item (#1532)
This commit is contained in:
parent
168257605f
commit
ab97336e89
@ -110,6 +110,7 @@ Here is an example:
|
|||||||
| `formatStrong` | <kbd>CmdOrCtrl</kbd>+<kbd>B</kbd> | Set the font of the selected text to bold |
|
| `formatStrong` | <kbd>CmdOrCtrl</kbd>+<kbd>B</kbd> | Set the font of the selected text to bold |
|
||||||
| `formatEmphasis` | <kbd>CmdOrCtrl</kbd>+<kbd>I</kbd> | Set the font of the selected text to italic |
|
| `formatEmphasis` | <kbd>CmdOrCtrl</kbd>+<kbd>I</kbd> | Set the font of the selected text to italic |
|
||||||
| `formatUnderline` | <kbd>CmdOrCtrl</kbd>+<kbd>U</kbd> | Change the selected text to underline |
|
| `formatUnderline` | <kbd>CmdOrCtrl</kbd>+<kbd>U</kbd> | Change the selected text to underline |
|
||||||
|
| `highlight` | <kbd>CmdOrCtrl</kbd>+<kbd>Shift</kbd>+<kbd>H</kbd> | Highlight the selected text by <mark> tag |
|
||||||
| `formatInlineCode` | <kbd>CmdOrCtrl</kbd>+<kbd>`</kbd> | Change the selected text to inline code |
|
| `formatInlineCode` | <kbd>CmdOrCtrl</kbd>+<kbd>`</kbd> | Change the selected text to inline code |
|
||||||
| `formatInlineMath` | <kbd>CmdOrCtrl</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd> | Change the selected text to inline math |
|
| `formatInlineMath` | <kbd>CmdOrCtrl</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd> | Change the selected text to inline math |
|
||||||
| `formatStrike` | <kbd>CmdOrCtrl</kbd>+<kbd>D</kbd> | Strike through the selected text |
|
| `formatStrike` | <kbd>CmdOrCtrl</kbd>+<kbd>D</kbd> | Strike through the selected text |
|
||||||
|
@ -84,6 +84,7 @@ class Keybindings {
|
|||||||
['formatStrong', 'CmdOrCtrl+B'],
|
['formatStrong', 'CmdOrCtrl+B'],
|
||||||
['formatEmphasis', 'CmdOrCtrl+I'],
|
['formatEmphasis', 'CmdOrCtrl+I'],
|
||||||
['formatUnderline', 'CmdOrCtrl+U'],
|
['formatUnderline', 'CmdOrCtrl+U'],
|
||||||
|
['highlight', 'Shift+CmdOrCtrl+H'],
|
||||||
['formatInlineCode', 'CmdOrCtrl+`'],
|
['formatInlineCode', 'CmdOrCtrl+`'],
|
||||||
['formatInlineMath', 'Shift+CmdOrCtrl+M'],
|
['formatInlineMath', 'Shift+CmdOrCtrl+M'],
|
||||||
['formatStrike', 'CmdOrCtrl+D'],
|
['formatStrike', 'CmdOrCtrl+D'],
|
||||||
|
@ -44,6 +44,14 @@ export default function (keybindings) {
|
|||||||
click (menuItem, browserWindow) {
|
click (menuItem, browserWindow) {
|
||||||
actions.format(browserWindow, 'sub')
|
actions.format(browserWindow, 'sub')
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
id: 'highlightMenuItem',
|
||||||
|
label: 'Highlight',
|
||||||
|
type: 'checkbox',
|
||||||
|
accelerator: keybindings.getAccelerator('highlight'),
|
||||||
|
click (menuItem, browserWindow) {
|
||||||
|
actions.format(browserWindow, 'mark')
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
}, {
|
}, {
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
html {
|
@keyframes loading {
|
||||||
-webkit-font-smoothing: antialiased;
|
0% {
|
||||||
}
|
-webkit-transform: rotate(0deg);
|
||||||
|
transform: rotate(0deg);
|
||||||
pre {
|
}
|
||||||
-webkit-font-smoothing: auto;
|
100% {
|
||||||
|
-webkit-transform: rotate(360deg);
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes highlight {
|
@keyframes highlight {
|
||||||
@ -18,15 +21,37 @@ pre {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes loading {
|
html {
|
||||||
0% {
|
-webkit-font-smoothing: antialiased;
|
||||||
-webkit-transform: rotate(0deg);
|
}
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
pre {
|
||||||
100% {
|
-webkit-font-smoothing: auto;
|
||||||
-webkit-transform: rotate(360deg);
|
}
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
mark {
|
||||||
|
display: inline-block;
|
||||||
|
height: 1.2em;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
mark::before,
|
||||||
|
mark::after {
|
||||||
|
clip-path: inset(100%);
|
||||||
|
clip: rect(1px, 1px, 1px, 1px);
|
||||||
|
height: 1px;
|
||||||
|
overflow: hidden;
|
||||||
|
position: absolute;
|
||||||
|
white-space: nowrap;
|
||||||
|
width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
mark::before {
|
||||||
|
content: " [highlight start] ";
|
||||||
|
}
|
||||||
|
|
||||||
|
mark::after {
|
||||||
|
content: " [highlight end] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ag-editor-id summary {
|
#ag-editor-id summary {
|
||||||
|
@ -206,6 +206,10 @@ export const FORMAT_MARKER_MAP = {
|
|||||||
sup: {
|
sup: {
|
||||||
open: '<sup>',
|
open: '<sup>',
|
||||||
close: '</sup>'
|
close: '</sup>'
|
||||||
|
},
|
||||||
|
mark: {
|
||||||
|
open: '<mark>',
|
||||||
|
close: '</mark>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ const addFormat = (type, block, { start, end }) => {
|
|||||||
}
|
}
|
||||||
case 'sub':
|
case 'sub':
|
||||||
case 'sup':
|
case 'sup':
|
||||||
|
case 'mark':
|
||||||
case 'u': {
|
case 'u': {
|
||||||
const MARKER = FORMAT_MARKER_MAP[type]
|
const MARKER = FORMAT_MARKER_MAP[type]
|
||||||
const oldText = block.text
|
const oldText = block.text
|
||||||
@ -133,7 +134,7 @@ const addFormat = (type, block, { start, end }) => {
|
|||||||
const checkTokenIsInlineFormat = token => {
|
const checkTokenIsInlineFormat = token => {
|
||||||
const { type, tag } = token
|
const { type, tag } = token
|
||||||
if (FORMAT_TYPES.includes(type)) return true
|
if (FORMAT_TYPES.includes(type)) return true
|
||||||
if (type === 'html_tag' && /^(?:u|sub|sup)$/i.test(tag)) return true
|
if (type === 'html_tag' && /^(?:u|sub|sup|mark)$/i.test(tag)) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user