diff options
Diffstat (limited to 'kata.go')
| -rw-r--r-- | kata.go | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -0,0 +1,42 @@ +// Copyright 2020, Shulhan <m.shulhan@gmail.com>. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package kbbi + +import "golang.org/x/net/html" + +// +// Kata store the single root word and its definitions. +// +type Kata struct { + Dasar string `json:"dasar"` + Definisi []*DefinisiKata `json:"definisi"` +} + +// +// parseKataDasar given an HMTL element "h2" find a possible root word and +// return true; otherwise it will return false. +// +func (kata *Kata) parseKataDasar(h2 *html.Node) bool { + el := getFirstChild(h2) + if el.Data != tagNameSpan { + return false + } + for _, attr := range el.Attr { + if attr.Key != attrNameClass { + continue + } + if attr.Val != attrValueRootWord { + continue + } + el = getFirstChild(el) + if el.Data != tagNameAnchor { + return false + } + el = getFirstChild(el) + kata.Dasar = el.Data + return true + } + return false +} |
