aboutsummaryrefslogtreecommitdiff
path: root/src/html.nim
blob: 4ae5ee113b55e1979301fbe428632887e0b23932 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
type Html = object
  tags: seq[string]

type Tag {.acyclic.} = object
  name: string
  text: string
  nested: seq[Tag]

func parseHTML(html: string): Html = discard

# Todo: revamp parsing: keep track of tags, entities, etc
proc renderHTML*(html: string) =
  var
    in_angle = false
    in_body = false

  # _Why_ is it i, c and not c, i...
  for i, c in html:
    if c == '<':
      in_angle = true
      if html[i..i+4] == "<body":
        in_body = true
    elif c == '>':
      in_angle = false
    elif not in_angle and in_body and c in {char(32)..char(126), '\n'}:
      stdout.write(c)

proc renderSource*(html: string) =
  for i, c in html:
    stdout.write(c)