Skip to content

Commit

Permalink
Markdown block live preview: improved contrast
Browse files Browse the repository at this point in the history
Now Markdown markers in each token are dimmed to increase contrast
between the marker and the token's content.
  • Loading branch information
Ferdev committed Jun 22, 2018
1 parent 13f306d commit 0a98895
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions modules/markdown/assets/css/jetpack-markdown-block.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

.wp-block-jetpack-markdown-block-placeholder {
opacity: 0.5;
pointer-events: none;
}
.wp-block-jetpack-markdown-block-live-preview p {
min-height: 1.8em;
}
.wp-block-jetpack-markdown-block__live-preview__token {
/* $dark-gray-300 from Gutenberg _colors.scss */
color: #6c7781;
}
11 changes: 6 additions & 5 deletions modules/markdown/assets/js/components/markdown-live-preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ const markdownIt = new MarkdownIt( 'zero' ).enable( [
* to each token's content, the delimiter the user used (which the parser
* obviously removes in the resulting HTML)
*/
const LIVE_PREVIEW_TOKEN_CSS_CLASS = 'wp-block-jetpack-markdown-block__live-preview__token';

// Adds `_` or `*` to the beginning of the em tag
markdownIt.renderer.rules.em_open = function( tokens, idx ) {
const token = tokens[ idx ];
return `<em>${ token.markup }`;
return `<em><span class="${ LIVE_PREVIEW_TOKEN_CSS_CLASS }">${ token.markup }</span>`;
};
// Adds `_` or `*` to the end of the em tag
markdownIt.renderer.rules.em_close = function( tokens, idx ) {
const token = tokens[ idx ];
return `${ token.markup }</em>`;
return `<span class="${ LIVE_PREVIEW_TOKEN_CSS_CLASS }">${ token.markup }</span></em>`;
};
// Adds `__` or `**` to the beginning of the strong tag
markdownIt.renderer.rules.strong_open = function( tokens, idx ) {
const token = tokens[ idx ];
return `<strong>${ token.markup }`;
return `<strong><span class="${ LIVE_PREVIEW_TOKEN_CSS_CLASS }">${ token.markup }</span>`;
};
// Adds `__` or `**` to the end of the strong tag
markdownIt.renderer.rules.strong_close = function( tokens, idx ) {
const token = tokens[ idx ];
return `${ token.markup }</strong>`;
return `<span class="${ LIVE_PREVIEW_TOKEN_CSS_CLASS }">${ token.markup }</span></strong>`;
};
// Wraps inline code tokens with ```
markdownIt.renderer.rules.code_inline = function( tokens, idx ) {
Expand All @@ -61,7 +62,7 @@ markdownIt.renderer.rules.heading_open = function( tokens, idx ) {
if ( text_token ) {
text_token.content = ` ${ text_token.content }`;
}
return `<${ token.tag }>${ token.markup }`;
return `<${ token.tag }><span class="${ LIVE_PREVIEW_TOKEN_CSS_CLASS }">${ token.markup }</span>`;
};

const renderHTML = function( source ) {
Expand Down

0 comments on commit 0a98895

Please sign in to comment.