0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

シンタックスハイライターを作りたい!!

Posted at

javascriptでシンタックスハイライターを作りたい

まずはこれを見てください↓

sample.js
function helloworld(){
  console.log("hello world");
}

これはシンタックスハイライトと言って、コードを読みやすくするために
特定の文字を色付けする技術です。
今回はこれを自作してみようと思います。

1.ファイルの用意

早速作っていこうと思いますがまずファイルを用意しようと思います

今回必要なファイル

1.code.html   シンタックスハイライトしてほしいコードを書きます
2.script.js ハイライト処理をしていきます

今回はこれだけです。

それぞれのコードは

code.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>コード</title>
     
</head>
<body>
<script src ="script.js"></script>
  <pre><code>function helloworld(){
    console.log("hello world");
}</code></pre>
</body>
</html>

コード部分は適当です

script.js
document.addEventListener('DOMContentLoaded', (event) => {
var code = document.getElementsByTagName("code");

});

これで準備は出来ました
次は次回で

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?