Skip to content

Commit b7bb804

Browse files
authored
Adjust html markdown converter (#13)
* trim newline of EOF * apply triming * switch markdown builder * bump markdown
1 parent ef700fc commit b7bb804

18 files changed

+148
-58
lines changed

WORKSPACE

+30-2
Original file line numberDiff line numberDiff line change
@@ -1283,8 +1283,8 @@ go_repository(
12831283
go_repository(
12841284
name = "org_golang_x_net",
12851285
importpath = "golang.org/x/net",
1286-
sum = "h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=",
1287-
version = "v0.0.0-20201021035429-f5854403a974",
1286+
sum = "h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=",
1287+
version = "v0.0.0-20201110031124-69a78807bb2b",
12881288
)
12891289

12901290
go_repository(
@@ -1392,6 +1392,34 @@ go_repository(
13921392
version = "v1.2.1",
13931393
)
13941394

1395+
go_repository(
1396+
name = "com_github_andybalholm_cascadia",
1397+
importpath = "github.com/andybalholm/cascadia",
1398+
sum = "h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=",
1399+
version = "v1.2.0",
1400+
)
1401+
1402+
go_repository(
1403+
name = "com_github_johanneskaufmann_html_to_markdown",
1404+
importpath = "github.com/JohannesKaufmann/html-to-markdown",
1405+
sum = "h1:UGTGZeFq6ljcd6CSxLW+CzUXQQDMJMzQIQ4lVexFCOk=",
1406+
version = "v1.2.0",
1407+
)
1408+
1409+
go_repository(
1410+
name = "com_github_puerkitobio_goquery",
1411+
importpath = "github.com/PuerkitoBio/goquery",
1412+
sum = "h1:j7taAbelrdcsOlGeMenZxc2AWXD5fieT1/znArdnx94=",
1413+
version = "v1.6.0",
1414+
)
1415+
1416+
go_repository(
1417+
name = "com_github_sebdah_goldie_v2",
1418+
importpath = "github.com/sebdah/goldie/v2",
1419+
sum = "h1:hh70HvG4n3T3MNRJN2z/baxPR8xutxo7JVxyi2svl+s=",
1420+
version = "v2.5.1",
1421+
)
1422+
13951423
go_rules_dependencies()
13961424

13971425
go_register_toolchains()

content/BUILD.bazel

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@io_bazel_rules_go//go:def.bzl", "go_library")
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22

33
go_library(
44
name = "go_default_library",
@@ -7,6 +7,7 @@ go_library(
77
"client.go",
88
"deploy.go",
99
"download.go",
10+
"markdown.go",
1011
"syncdata.go",
1112
],
1213
importpath = "github.com/kogai/k9bookshelf/content",
@@ -15,9 +16,16 @@ go_library(
1516
"//gqlgenc/client:go_default_library",
1617
"@com_github_bold_commerce_go_shopify//:go_default_library",
1718
"@com_github_gomarkdown_markdown//:go_default_library",
18-
"@com_github_mattn_godown//:go_default_library",
19+
"@com_github_johanneskaufmann_html_to_markdown//:go_default_library",
1920
"@com_github_vbauerster_mpb//:go_default_library",
2021
"@com_github_vbauerster_mpb//decor:go_default_library",
2122
"@com_github_yamashou_gqlgenc//client:go_default_library",
2223
],
2324
)
25+
26+
go_test(
27+
name = "go_default_test",
28+
srcs = ["markdown_test.go"],
29+
embed = [":go_default_library"],
30+
deps = ["@in_gopkg_go_playground_assert_v1//:go_default_library"],
31+
)

content/download.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package content
33
import (
44
"os"
55
"path"
6-
"strings"
76
"sync"
87

9-
"github.com/mattn/godown"
108
"github.com/vbauerster/mpb"
119
"github.com/vbauerster/mpb/decor"
1210
)
@@ -31,7 +29,13 @@ func dowloadContens(output string, contents *[]Content, bar *mpb.Bar) error {
3129
c <- err
3230
return
3331
}
34-
err = godown.Convert(file, strings.NewReader(descriptionHTML), nil)
32+
md, err := htmlToMarkdown(descriptionHTML)
33+
if err != nil {
34+
c <- err
35+
return
36+
}
37+
38+
_, err = file.WriteString(md)
3539
if err != nil {
3640
c <- err
3741
return

content/markdown.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package content
2+
3+
import (
4+
md "github.com/JohannesKaufmann/html-to-markdown"
5+
)
6+
7+
func htmlToMarkdown(html string) (string, error) {
8+
opt := &md.Options{
9+
HorizontalRule: "---",
10+
}
11+
12+
converter := md.NewConverter("", true, opt)
13+
markdownStr, err := converter.ConvertString(html)
14+
if err != nil {
15+
return "", err
16+
}
17+
return markdownStr + "\n", nil
18+
}

content/markdown_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package content
2+
3+
import (
4+
"testing"
5+
6+
"gopkg.in/go-playground/assert.v1"
7+
)
8+
9+
func TestHtmlToMarkdown(t *testing.T) {
10+
t.Parallel()
11+
md, err := htmlToMarkdown(`<p>abc</p>`)
12+
assert.Equal(t, nil, err)
13+
assert.Equal(t, `abc
14+
`, md)
15+
}
16+
17+
func TestHtmlToMarkdownList(t *testing.T) {
18+
t.Parallel()
19+
md, err := htmlToMarkdown(`<ul><li>abc</li></ul><p>def</p>`)
20+
assert.Equal(t, nil, err)
21+
assert.Equal(t, `- abc
22+
23+
def
24+
`, md)
25+
}
26+
27+
func TestHtmlToMarkdownListAndBold(t *testing.T) {
28+
t.Parallel()
29+
md, err := htmlToMarkdown(`<ul><li>abc</li></ul><b>def</b>`)
30+
assert.Equal(t, nil, err)
31+
assert.Equal(t, `- abc
32+
33+
**def**
34+
`, md)
35+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
- リッチエディタは使いたくない
22
- theme-kitのような体験でコンテンツを更新したい
33
- 手元のエディタで更新したいので、管理画面は拡張しない
4-
- Private AppとしてAPI Secretだけ使うようにする
4+
- Private AppとしてAPI Secretだけ使うようにする
55
- admin apiで取得・更新
66
- 商品データはGraphQL APIで取得・更新出来る
7-
- gqlgencでAPIクライアントを生成
8-
- bazelでビルドすると、APIクライアントの生成元として使われている*.gotplファイルがbazelのサンドボックスに入らない
9-
- go_repositoryにpatchを当てて*.gotplもbazelのサンドボックスにexportされるようにする
7+
- gqlgencでAPIクライアントを生成
8+
- bazelでビルドすると、APIクライアントの生成元として使われている"\*.gotpl"ファイルがbazelのサンドボックスに入らない
9+
- go\_repositoryにpatchを当てて\*.gotplもbazelのサンドボックスにexportされるようにする
1010
- ページ・ブログ(アーティクル)はREST APIで取得・更新出来る
11-
- ブログ記事はblog->articleの階層構造を持つので、商品やページとは少し異なる
12-
- bold-commerceのgo-shopifyが必要十分
11+
- ブログ記事はblog->articleの階層構造を持つので、商品やページとは少し異なる
12+
- bold-commerceのgo-shopifyが必要十分
1313
- articleリソースは存在しないが、簡単に拡張出来るAPIを持っている
1414
- HTML/Markdownの相互変換は非決定的なので、差分の解消が課題
15-
- 順序なしリスト要素を`-``*`のどちらで表現するか、など
15+
- 順序なしリスト要素を`-``*`のどちらで表現するか、など
1616
- メタデータのハンドリングも出来るようにすれば、さらに捗るかも
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
以下の書籍が入荷しました。
22

3-
* [Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages](https://k9bookshelf.com/products/language-implementation-patterns-create-your-own-domain-specific-and-general-programming-languages)
4-
* [Node.js Design Patterns - Third edition: Design and implement production-grade Node.js applications using proven patterns and techniques](https://k9bookshelf.com/products/node-js-design-patterns-third-edition-design-and-implement-production-grade-node-js-applications-using-proven-patterns-and-techniques)
5-
* [The Maker’s Guide to the Zombie Apocalypse: Defend Your Base with Simple Circuits, Arduino, and Raspberry Pi](https://k9bookshelf.com/products/the-makers-guide-to-the-zombie-apocalypse-defend-your-base-with-simple-circuits-arduino-and-raspberry-pi)
6-
* [Programming Webassembly with Rust: Unified Development for Web, Mobile, and Embedded Applications (1ST ed.)](https://k9bookshelf.com/products/programming-webassembly-with-rust)
7-
3+
- [Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages](https://k9bookshelf.com/products/language-implementation-patterns-create-your-own-domain-specific-and-general-programming-languages)
4+
- [Node.js Design Patterns - Third edition: Design and implement production-grade Node.js applications using proven patterns and techniques](https://k9bookshelf.com/products/node-js-design-patterns-third-edition-design-and-implement-production-grade-node-js-applications-using-proven-patterns-and-techniques)
5+
- [The Maker’s Guide to the Zombie Apocalypse: Defend Your Base with Simple Circuits, Arduino, and Raspberry Pi](https://k9bookshelf.com/products/the-makers-guide-to-the-zombie-apocalypse-defend-your-base-with-simple-circuits-arduino-and-raspberry-pi)
6+
- [Programming Webassembly with Rust: Unified Development for Web, Mobile, and Embedded Applications (1ST ed.)](https://k9bookshelf.com/products/programming-webassembly-with-rust)

contents/pages/contact.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
k9bookshelfに関するお問い合わせはこちらからお願いいたします。
2-
3-

contents/pages/このサイトについて.md

-2
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@
1515
また、日本語書籍より更に膨大な流量がある英語書籍の中から、時にはマイナーなテーマについての書籍で、さらに一定の評価を得ているものを探す、となるとこれは中々に困難です。
1616

1717
このサイトで紹介する書籍が、そのギャップを埋めることができれば嬉しく思います。
18-
19-

contents/products/an-introduction-to-functional-programming-through-lambda-calculus-dover-books-on-mathematics.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
表題にはIntroductionとありますが、パラダイムの入門書的な内容はあまり期待できません。 関数型言語が、少なくとも理論的にはどういうモデルの上に立っているかが観察できるところが興味深い本です。
44

5-
静的型付き言語界隈の精神的・物理的鈍器として紹介されることの多い[型システム入門](https://amzn.to/36V7U6b)という書籍がありますが、本書を読んでから挑戦してみると面白いかも知れません。 というのもラムダ計算を基に関数型言語を構築していくというこの本の主題である要素を、型システム入門でも理論的な解説を踏まえながら追っていくからです。 ただ、本書の方がコードでの解説によりフォーカスしており、「まず動かしてみて学ぶ」というような学び方には合っていると思います。
6-
7-
5+
静的型付き言語界隈の精神的・物理的鈍器として紹介されることの多い [型システム入門](https://amzn.to/36V7U6b) という書籍がありますが、本書を読んでから挑戦してみると面白いかも知れません。 というのもラムダ計算を基に関数型言語を構築していくというこの本の主題である要素を、型システム入門でも理論的な解説を踏まえながら追っていくからです。 ただ、本書の方がコードでの解説によりフォーカスしており、「まず動かしてみて学ぶ」というような学び方には合っていると思います。

contents/products/blood-sweat-and-pixels-the-triumphant-turbulent-stories-behind-how-video-games-are-made.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
一見華やかな印象のゲーム業界を支えるその現場が、まさにBloodとSweatで贖われていること、それでもなお開発者達を引きつけてやまない抗いがたい魅力があることがよく分かります。 (自分でやりたいかと問われるとその覚悟はないですが。。。)
44

55
ビジネスツールやウェブサービスの運営を生業にしていても、開発プロジェクトのドキュメンタリーとして十分に共感して楽しめる内容になっていると思います。 個人的にはDiablo3の不死鳥のようなエピソードが好きです。
6-
7-

contents/products/language-implementation-patterns-create-your-own-domain-specific-and-general-programming-languages.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ The pattern implementations use Java, but the patterns themselves are completely
1010

1111
You’ll learn to create configuration file readers, data readers, model-driven code generators, source-to-source translators, source analyzers, and interpreters. Each chapter groups related design patterns and, in each pattern, you’ll get hands-on experience by building a complete sample implementation. By the time you finish the book, you’ll know how to solve most common language implementation problems.
1212

13-
1413
---
1514

1615
表題の通り、言語実装のデザインパターンを色々紹介していく本です。 いくつかのパートに分けて言語解析器、インタープリタ、コンパイラ(Translator&Generatorとして紹介)の内部に現れるパターンを紹介していきます。
@@ -19,8 +18,6 @@ You’ll learn to create configuration file readers, data readers, model-driven
1918

2019
LinterやFormatter、設定ファイルの解析器、あるいはマークダウンのような軽量マークアップ言語からHTMLを生成するなど、言語実装におけるパターンの適用範囲は実は一般的なプログラマーにとっても身近なものであるというのです。 (あるい単に教養として、ということでも良いかも知れません)
2120

22-
私はこの本にあたった後に、i18nの辞書となるjsonファイルからTypeScriptなどの型定義ファイルを生成するという[ツール](https://github.com/kogai/typed_i18n)を書いたことがあるのですが、 この本に出てくるコンセプトが溶け込んでいたと言って良いと思います。 例えば入力であるjsonを何らかの中間表現に落とし込み、IRをGeneratorが型定義として書き出すといったような、この本で解説されているパターンです。
21+
私はこの本にあたった後に、i18nの辞書となるjsonファイルからTypeScriptなどの型定義ファイルを生成するという [ツール](https://github.com/kogai/typed_i18n) を書いたことがあるのですが、 この本に出てくるコンセプトが溶け込んでいたと言って良いと思います。 例えば入力であるjsonを何らかの中間表現に落とし込み、IRをGeneratorが型定義として書き出すといったような、この本で解説されているパターンです。
2322

2423
LinterやFormatterを常用してレポジトリを管理することは一般的になっていますし、チーム毎に適用したいルールというものも出てくるでしょう。 そういった時の道案内にも良いと思います。
25-
26-

contents/products/node-js-design-patterns-third-edition-design-and-implement-production-grade-node-js-applications-using-proven-patterns-and-techniques.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Learn proven patterns, techniques, and tricks to take full advantage of the Node
44

55
**Key Features**
66

7-
* Learn how to create solid server-side applications by leveraging the full power of Node.js 14
8-
* Understand how Node.js works and learn how to take full advantage of its core components as well as the solutions offered by its ecosystem
9-
* Avoid common mistakes and use proven patterns to create production grade Node.js applications
7+
- Learn how to create solid server-side applications by leveraging the full power of Node.js 14
8+
- Understand how Node.js works and learn how to take full advantage of its core components as well as the solutions offered by its ecosystem
9+
- Avoid common mistakes and use proven patterns to create production grade Node.js applications
1010

1111
**Book Description**
1212

@@ -18,20 +18,19 @@ Throughout the book, you’ll see Node.js in action with the help of several rea
1818

1919
**What you will learn**
2020

21-
* Become comfortable with writing asynchronous code by leveraging callbacks, promises, and the async/await syntax
22-
* Leverage Node.js streams to create data-driven asynchronous processing pipelines
23-
* Implement well-known software design patterns to create production grade applications
24-
* Share code between Node.js and the browser and take advantage of full-stack JavaScript
25-
* Build and scale microservices and distributed systems powered by Node.js
26-
* Use Node.js in conjunction with other powerful technologies such as Redis, RabbitMQ, ZeroMQ, and LevelDB
21+
- Become comfortable with writing asynchronous code by leveraging callbacks, promises, and the async/await syntax
22+
- Leverage Node.js streams to create data-driven asynchronous processing pipelines
23+
- Implement well-known software design patterns to create production grade applications
24+
- Share code between Node.js and the browser and take advantage of full-stack JavaScript
25+
- Build and scale microservices and distributed systems powered by Node.js
26+
- Use Node.js in conjunction with other powerful technologies such as Redis, RabbitMQ, ZeroMQ, and LevelDB
2727

2828
**Who this book is for**
2929

3030
This book is for developers and software architects who have some prior basic knowledge of JavaScript and Node.js and now want to get the most out of these technologies in terms of productivity, design quality, and scalability. Software professionals with intermediate experience in Node.js and JavaScript will also find valuable the more advanced patterns and techniques presented in this book.
3131

3232
This book assumes that you have an intermediate understanding of web application development, databases, and software design principles.
3333

34-
3534
---
3635

3736
Node.jsでコードを書くときのデザインプラクティスやそのプラクティスが重要である理由について解説した書籍です。 JavaScriptのイベントループによる実行モデルを、時に分かりやすい図を挟みながら詳細に解説が載っています。 業務でJavaScriptを書いていて、普通に書けるようにはなってきたけど、もう一歩深入りしたいという方にオススメです。(特にJavaScriptが最初の言語である方)
@@ -41,5 +40,3 @@ JavaScriptのイベントループモデルは、「WebブラウザというGUI
4140
この本では、あまり語られることのない、JavaScriptが「どうやって」「なぜそのように」実行されているのかということが解説されています。 (表題のDesign Patternは、「そういう理由であるからこういったデザインを採用する」という意味と解釈しています)
4241

4342
なお、表題のイメージとは異なり、いわゆるデザパタ本的な性質は薄いです。
44-
45-

0 commit comments

Comments
 (0)