When creating the script, I was actually tempted to call the script “Press F to Furigana”.
Love it
Mad 尊敬
Hey, just want to let you know that this probably doesn’t work with Safari, as it doesn’t seem to support lookaheads
I cannot verify it as I don’t have a Mac, but I think lookaheads should be supported by all browsers. Only lookbehind is a newer feature and not supported by Safari and some other browsers, which is why I have put it into a try/catch block.
Sorry, that was a bug. The intended behavior for IME2Furigana is to stay in the selected mode across tabs and browser sessions. This should be fixed now.
Version 1.7 patch notes:
- Bugfix: on page load, mode “off” would always reset to “on”
- Bugfix: if the text editor is closed and the mode is changed in another tab, an error would occur
- Now using the CSS variable provided by Discourse for the background color of the confirmation prompt (
--tertiary-low
) - Now using
textContent
instead of the slowerinnerText
to set the text in HTML elements
Ah, sorry about that
No problem. I also had forgotten that we have already talked about basically the same thing about a year ago and just noticed it now while looking at my older patch notes
Omg, I have no memory of this. Nor of the problems with the Heatmap. lol
@Wildjinjer this is the script I use for spoiler furigana
No need to write out the code manually
On the first introduction, I immediately found a bug.
Everything inside code blocks, like ` or ``` or <pre>
, should not be collapsed to Furigana shorthand. Otherwise, literal <元>[もと]
cannot be typed with the UserScript on.
The rendering still appears to be correct, though.
You call it a bug, I call it intended behavior
I’m aware of this behavior and I personally would also prefer code blocks to not be affected, but I did not manage to inject my code directly into the “cooking process” of Markdown-it as a rule alongside the existing rules, but only as a preprocessing step. So I would have to replicate the existing Markdown-it rules in my code to apply the ruby conversion only at the correct places. Since the “cooking” is performed after every character input, I did not want to add too many additional computations, so I decided that the use case “furigana markup inside code block” comes up too rarely to warrant the additional necessary computations. And since the markup => ruby conversion does not take code blocks into account, I decided that ruby => markup should also ignore code blocks to at least be consistent across these two directions.
What do you think of [spoiler]
'd Furigana in [details]
?
[details=巧み]
Details is dead.
[/details]
It seems that Furigana in [details]
itself doesn’t work either.
<ruby lang = 'ja-JP'>巧<rp>(</rp><rt>たく</rt><rp>)</rp></ruby>み
Ruby is dead.
Though, of course it can be done with vanilla HTML.
I still can’t find a way to shorthand render Furigana without auto-inserting Furigana, or blur mode.
That is a limitation of the native [details]
markup rule, so I don’t think it has anything to do with IME2Furigana? The HTML workaround also works with IME2Furigana:
<details><summary><振>[ふ]り<仮名>[がな]</summary>Hidden text</details>
振り仮名
Hidden textNative markup is also incompatible with [details]
, so IME2Furigana is not even a special case:
[details="Some **bold** text"]
Hidden Text
[/details]
Some **bold** text
Hidden Text
The workaround you have linked for blurred furigana is not possible to achieve with furigana markup, but it does not work that well anyway since it places the furigana below the base text instead of above:
Like this?
That’s right.
Looks for me like
Originally, IME2Furigana only converted IME input to ruby – I added the furigana markup functionality half a year later, but did not want to increase the number of modes you have to go through when clicking the F button, so I kept it at the three existing modes. Maybe I should at some point add a proper settings menu for this script so that it can be more customized. For now, you would have to disable IME2Furigana, write your post, and then reenable it before sending your post.
Hmm? Why is it below? For me, it is above for both Firefox for Linux and Firefox for Android.
Seems like Firefox places it above and Chromium (tested with Google Chrome and Microsoft Edge on Windows 10 and Android) places it below and left-aligned. Using <span class="spoiler">
instead of [spoiler]
<details><summary><ruby>漢字<rt><span class="spoiler">かんじ</span></rt></ruby></summary>Hidden text</details>
seems to work better:
漢字
Hidden textI have just figured it out. OFF mode should still be to parse custom syntax, although shouldn’t auto-insert Furigana on entry.
Change Line 147-148 from
if (event.data.length === 0) return;
furigana = mode ? furigana.replace(/n/g, "ん") : '';
To,
if (event.data.length === 0) return;
furigana = mode ? furigana.replace(/n/g, "ん") : '';
Delete Line 255-258
if (!mode) {
removeBanner();
return raw;
}
Then, this works 世界.
I think there should still be a mode which entirely prevents IME2Furigana from tampering with the user input without disabling the script in Tampermonkey and reloading the page. If I decide to add the possibility to have markup => ruby conversion enabled and IME => markup conversion disabled, it will be in the form of an optional fourth mode and not a modification of one of the existing modes.
And I will probably change the script in the next version to use <span class="spoiler">
instead of [spoiler]
.
Nonetheless, I updated to a version with 4 modes with code-block detection, in case someone need it. (Press “Raw” button to add to TamperMonkey)
Change Logs
- 6 May 2022
- Add label for every Options
- Add Option
CONVERT_ONLY_SPECIAL_MARKUP
- only exactly<ruby lang = 'ja-JP'>
will be converted back to markup. Everything else including<ruby>
will be ignored.
- 1 May 2022
- Add Furigana detection for small Kana (ヵヶ).
- 29 Apr 2022
- Force update textarea for Kiwi Browser for Android (with Violentmonkey).
- 25 Apr 2022
- Change
@name
, so that it can co-exist with the original script. Also, update@description
.
- Change
- 24 Apr 2022
- Add 々 to Kanji list (so that 久々 works)
- Add zero-width space
\u200b
,\u2060
support. Copy and paste the character just behind<
(in<>[]
or<>{}
) to prevent conversion to<ruby>
tags - <振り仮名>[ふりがな]- I made it work to prevent
<ruby>
collapse as well, by putting the weird space just behind<ruby>
- 振り仮名
- I made it work to prevent
- Add a settings to turn off
CODE_BLOCK_DETECTION
, in case it fails.
- 12 Apr 2022
- Don’t autocollapse
<ruby>
tags (to<>[]
/<>{}
) on edit- It still will collapse on Initialization, on Paste, on Lose Focus (onblur), or on Save.
- Don’t collapse, if nested
<ruby>
tags (危険な秘密を) - JoJo's Bizarre Adventure Book Club (Volume 5) 「最後の波紋」 - #13 by polv (Admittedly, this is a temporary fix.)
- Don’t autocollapse
<ruby><ruby>危<rt>き</rt></ruby><ruby>険<rt>けん</rt></ruby><rt>、、</rt></ruby><ruby>な<rt> 、</rt></ruby><ruby><ruby>秘<rt>ひ</rt></ruby><ruby>密<rt>みつ</rt></ruby><rt>、、</rt></ruby><ruby>を<rt> 、</rt></ruby>
- 12 Apr 2012
- Don’t collapse exotic
<ruby>
tags - 你好- Normal
<ruby >
tags can also be prevented from collapsing by adding a single space - 振り仮名
- Normal
- Restyle “blur” mode.
- Don’t collapse exotic
- 6 Apr 2022
- Allow OFF_MODE to be disabled. Also, if OFF_MODE is disabled, the change-mode button won’t be unnecesarily dimmed.
- 5 Apr 2022
- Add code block detection, for both ` and ```.
- Add “manual” mode - doesn’t auto-insert Furigana, but Furigana can still be rendered.
- Add two buttons, for inserting Furigana templates (
<>[]
/<>{}
) - Restyle “auto” mode.
- Default to
<span class="spoiler">
. The old[spoiler]
can still be detected. - Add UserScript icon
IME2振り仮名
This works <おはよう>[Hello]
- おはよう.
This also works - <ruby lang = 'ja-JP'>おはよう<rp>(</rp><rt>Hello</rt><rp>)</rp></ruby>
<ruby lang = 'ja-JP'>おはよう<rp>(</rp><rt>Hello</rt><rp>)</rp></ruby>