๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Daily/๊ธฐํƒ€

[ํ‹ฐ์Šคํ† ๋ฆฌ ๊พธ๋ฏธ๊ธฐ] ์ฝ”๋“œ๋ธ”๋ก ๋””์ž์ธ ๋ณ€๊ฒฝ

์ค€๋น„ ๊ณผ์ •

ํ‹ฐ์Šคํ† ๋ฆฌ ๊ด€๋ฆฌ์ž > ๊พธ๋ฏธ๊ธฐ - ์Šคํ‚จ ํŽธ์ง‘ > html ํŽธ์ง‘

 

+ ๋งŒ์•ฝ ์ด์ „์— ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ '์ฝ”๋“œ ๋ฌธ๋ฒ• ๊ฐ•์กฐ'๋ฅผ ์ ์šฉํ–ˆ๋‹ค๋ฉด ํ•ด์ œํ•˜๊ธฐ

 

1. ํ…Œ๋งˆ

1) ์•„๋ž˜ ์‚ฌ์ดํŠธ์—์„œ ์›ํ•˜๋Š” ํ…Œ๋งˆ ๊ณ ๋ฅด๊ธฐ

https://highlightjs.org/static/demo/

 

highlight.js demo

 

highlightjs.org

2) ํ…Œ๋งˆ ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ

 (1) ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ

 (2) ๋„์–ด์“ฐ๊ธฐ๋Š” -(ํ•˜์ดํ”ˆ)์œผ๋กœ ๋ณ€๊ฒฝ

 ex) Github Dark โ†’ github-dark

 ex) Base16 / Ashes โ†’ base16/ashes

 

3) html์˜ <head> </head> ์‚ฌ์ด์— ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

<!-- ์ฝ”๋“œ๋ธ”๋Ÿญ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€ -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/github-dark.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

 

2. ํฐํŠธ

1) ์•„๋ž˜์˜ ์‚ฌ์ดํŠธ์—์„œ ์›ํ•˜๋Š” ํฐํŠธ ๊ณ ๋ฅด๊ธฐ

https://fonts.google.com/

 

Browse Fonts - Google Fonts

Making the web more beautiful, fast, and open through great typography

fonts.google.com

 

2) ํฐํŠธ ๋ณต์‚ฌํ•˜๊ธฐ

 

3) html์˜ <head> </head> ์‚ฌ์ด์— ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

<!-- ์ฝ”๋“œ๋ธ”๋Ÿญ ํฐํŠธ -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR&display=swap" rel="stylesheet">

 

4) css์— ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

/* ์ฝ”๋“œ๋ธ”๋ก ํฐํŠธ style */
pre > code {
font-family: 'ํฐํŠธ ์ด๋ฆ„', monospace !important;
font-size: 15px;
}

- font-family: ํฐํŠธ ์ด๋ฆ„

- font-size: ํฐํŠธ ์‚ฌ์ด์ฆˆ

- (๊ทธ ์™ธ ํ•„์š”ํ•˜๋‹ค๋ฉด ๋‹ค๋ฅธ ๋ธ”๋กœ๊ทธ์—์„œ...)

 

 

3. ๋ผ์ธ ๋„˜๋ฒ„

1) html์˜ <head> </head> ์‚ฌ์ด์— ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

<!-- Line Number ์ ์šฉ -->
<script src="//cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.7.0/highlightjs-line-numbers.min.js"></script>
<script>hljs.initLineNumbersOnLoad();</script>

 

2) css์˜ ๋งจ ์•„๋ž˜์— ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

/* Line Number CSS */
/* for block of numbers */
.hljs-ln-numbers {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
text-align: center;
color: #B5B5B5;
border-right: 1px solid #B5B5B5;
vertical-align: top;
width: 20px;
padding-left: 0px;
}
/* your custom style here */
.hljs-ln td.hljs-ln-code {
padding-left: 15px;
}

 

3) ๋งŒ์•ฝ ์ ์šฉํ•œ ์ฝ”๋“œ๊ฐ€ ์ด๋ ‡๊ฒŒ ๋ณด์ธ๋‹ค๋ฉด... css์˜ table์„ ์ˆ˜์ •ํ•˜์ž

<์ฝ”๋“œ ์ˆ˜์ • ์ „>

 

<์ฝ”๋“œ ์ˆ˜์ • ํ›„>

 

<์ฝ”๋“œ ์ˆ˜์ • ์ „>

 

<์ฝ”๋“œ ์ˆ˜์ • ํ›„>

 

 

 

 

์ถœ์ฒ˜

https://dailylifeofdeveloper.tistory.com/361

https://one-hour.tistory.com/34