further improvements for the HTML parser

This commit is contained in:
rumpf_a@web.de
2010-02-14 09:59:01 +01:00
parent 597d98e7ee
commit 01fb99bc80
2 changed files with 73 additions and 2 deletions

67
lib/devel/graphics.nim Normal file
View File

@@ -0,0 +1,67 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2010 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements graphical output for Nimrod; the current
## implementation uses Cairo under the surface.
type
PSurface* = ref TSurface
TSurface {.pure, final.} = object
... # internal data
TRect* = tuple[x, y, width, height: int]
TPoint* = tuple[x, y: int]
TColor* = distinct int ## a color stored as RGB
proc `==` (a, b: TColor): bool {.borrow.}
# XXX maybe other operations for colors? What about saturated artithmetic?
const
colRed* = TColor(0x00ff0000) # RGB
colGreen* = ...
colBlue* = ...
colOrange* = ...
proc newSurface*(width, height: int): PSurface
proc color*(name: string): TColor
proc isColor*(name: string): bool
proc rgb*(r, g, b: range[0..255]): TColor
proc drawRect*(sur: PSurface, r: TRect, col: TColor)
proc fillRect*(sur: PSurface, r: TRect, col: TColor)
proc drawCircle*(sur: PSurface, mid: TPoint, radius: int)
proc drawCircle*(sur: PSurface, r: TRect)
proc fillCircle*(sur: PSurface, mid: TPoint, radius: int)
proc fillCircle*(sur: PSurface, r: TRect)
proc drawElipse*(sur: PSurface, r: TRect)
proc fillElipse*(sur: PSurface, r: TRect)
proc textBounds*(text: string): tuple[len, height: int]
proc drawText*(sur: PSurface, p: TPoint, text: string)
proc drawLine*(sur: PSurface, a, b: TPoint)
proc `[]`*(sur: PSurface, p: TPoint): TColor
proc `[,]`*(sur: PSurface, x, y: int): TColor
proc `[]=`*(sur: PSurface, p: TPoint, col: TColor)
proc `[,]=`*(sur: PSurface, x, y: int, col: TColor)
proc writeToPNG*(sur: PSurface, filename: string)

View File

@@ -152,7 +152,7 @@ const
tagOl, tagP, tagPre, tagTable, tagUl, tagCenter, tagDir, tagIsindex,
tagMenu, tagNoframes}
SingleTags* = {tagArea, tagBase, tagBasefont,
tagBr, tagCol, tagFrame, tagHr, tagImg, tagInput, tagIsindex,
tagBr, tagCol, tagFrame, tagHr, tagImg, tagIsindex,
tagLink, tagMeta, tagParam}
Entities = [
@@ -276,7 +276,7 @@ proc untilElementEnd(x: var TXmlParser, result: PXmlNode,
case x.kind
of xmlElementStart, xmlElementOpen:
case result.htmlTag
of tagLi, tagP, tagDt, tagDd, tagOption:
of tagLi, tagP, tagDt, tagDd, tagInput, tagOption:
if htmlTag(x.elementName) notin InlineTags:
# some tags are common to have no ``</end>``, like ``<li>``:
errors.add(expected(x, result))
@@ -285,6 +285,10 @@ proc untilElementEnd(x: var TXmlParser, result: PXmlNode,
if htmlTag(x.elementName) in {tagTr, tagTd, tagTh}:
errors.add(expected(x, result))
break
of tagOptgroup:
if htmlTag(x.elementName) in {tagOption, tagOptgroup}:
errors.add(expected(x, result))
break
else: nil
result.addNode(parse(x, errors))
of xmlElementEnd: