hypothesis-extension's People
hypothesis-extension's Issues
markdownエディタに置き換える
概要
- yarnのライブラリからmarkdownエディタを選定する
- chrome拡張内で使ってみる
候補
- https://github.com/mixmark-io/turndown
- https://zenn.dev/hayato94087/articles/649e8d817165d8#markdown%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95
editor
- https://docs.komagata.org/5467
- https://github.com/markedjs/marked
- 導入自体は簡単そう
- ドキュメントと使用例が多い
- メンテも頻繁にされていそう
- https://github.com/benweet/stackedit
- 導入が簡単そうだが、メンテが放棄されてそう
要件
- markdownエディタはページ上に表示する
- チェックボックスをサポートしている
- テキストエリアの拡大縮小は可能
- サーバーから送信されたテキストがあってもmarkdownとして変換し表示できる
設計メモ
-
エディタ部分は普通のテキストエリアで、プレビュー時のみmarkdown形式に表示するだけでいいのは
-
エディタ描画のタイミングについて
- 該当の要素がDOM内に追加されたタイミング時
- chrome拡張のapiでDOMの変更を検知できるものがあるかどうか
- MutaionEvent系のAPIは廃止されているっぽい
- MutationObserverを使うっぽい
- chrome拡張のapiでDOMの変更を検知できるものがあるかどうか
- 該当の要素がDOM内に追加されたタイミング時
-
描画方法について
- ドキュメントに対する変更を検知し、指定部分のテキストエリアの置き換えを行う
- write、previewの切り替えでテキストエリアと変換内容の切り替えを行う
- チェックボックスの変更はプレビュー部分からもできるようにしたい
調査メモ
- hypothesisによって追加された部分は基本的に
Shadow Dom
属性を持つ- そのため、内部の要素の取得には以下のようにして
.shadowRoot
を使う必要がある。
const shadowRoot = document.querySelector('hypothesis-sidebar').shadowRoot;
- そのため、内部の要素の取得には以下のようにして
- 上記でhypothesisによって追加された要素でも取得すること自体は可能
- ただし、内部の要素を書き換えようとすると「Uncaught DOMException: Blocked a frame with origin {URL} from accessing a cross-origin frame.」が表示される
- postMessageでの通信等をするためには、両ドメインのサイトが postMessage を実装している必要があるので、実現が難しそう
- ただし、内部の要素を書き換えようとすると「Uncaught DOMException: Blocked a frame with origin {URL} from accessing a cross-origin frame.」が表示される
- そのため、クロスドメインでのiframe内の要素の変更等は厳しそう
- 上記理由から、クライアント側の実装を変更する方針にする
markdownエディタをmilkdownに変更してみる
typescriptに置き換える
chrome拡張全体をreactに置き換える
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.