Skip to content

Apply a class to <em>'s containing Japanese characters - #94

Merged
smikitky merged 4 commits into
masterfrom
fix-emphasis
Feb 7, 2019
Merged

Apply a class to <em>'s containing Japanese characters#94
smikitky merged 4 commits into
masterfrom
fix-emphasis

Conversation

@smikitky

@smikitkysmikitky commented Feb 7, 2019

Copy link
Copy Markdown
Member

This fixes#22 .

  • Added a Gatsby custom plugin that iterates over markdown AST and add em-ja class to <em>'s that contain any Japanese character.
  • Added a CSS rule to render .em-ja with bold instead of italic.

環境によって日本語で em が正しくレンダリングされない問題を修正します。em で強調されている文字列に日本語文字が含まれている場合(例: *あああ*)、問答無用で太字にします。

もし yarn dev で太字が反映されない場合は yarn reset でキャッシュを削除してみてください。

const visit = require('unist-util-visit');

const hasJapanese = str => {
return /[\u30a0-\u30ff\u3040-\u309f\u3005-\u3006\u30e0-\u9fcf。、]/.test(str);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[imo]
hasJapanese から推測できますが、一応 regex の範囲についてコメントしておいても良いかもしれません。

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

念のため確認してたらCJK統合漢字のコードポイント間違ってました…(コピペ元から間違ってました)

@potato4dpotato4d left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2019-02-08 at 1 25 42

動作見ました。良さそうです!
一点、 imo を書いておいたので、もしよろしければ検討いただけるとー。

@smikitky

smikitky commented Feb 7, 2019

Copy link
Copy Markdown
MemberAuthor

@potato4d コメントを加えてみましたが、ああいうことでよかったでしょうか

@koba04koba04 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認しました。問題ないと思います 👍

@smikitky
smikitky merged commit 9dffa43 into masterFeb 7, 2019
@smikitky
smikitky deleted the fix-emphasis branch February 7, 2019 16:44
@potato4d

Copy link
Copy Markdown
Contributor

@smikitky 良いと思います〜!

@smikitkysmikitky added the workflow Working environment improvements including linting and CSS styles label Feb 13, 2019
@smikitkysmikitky mentioned this pull request Dec 1, 2021
7 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

workflowWorking environment improvements including linting and CSS styles

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Font issue related to <em>

3 participants

@smikitky@potato4d@koba04