Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | SHTML: add support for description list, tables, block comments |
---|---|
Timelines: | family | ancestors | descendants | both | sxhtml |
Files: | files | file ages | folders |
SHA3-256: |
b64d728a691ff205d6a5c70ecb92b335 |
User & Date: | stern 2023-02-20 22:09:46.201 |
Context
2023-02-22
| ||
14:58 | Rename 'sxpf.Value' to 'sxpf.Object' ... (check-in: 518da9dba1 user: stern tags: sxhtml) | |
2023-02-20
| ||
22:09 | SHTML: add support for description list, tables, block comments ... (check-in: b64d728a69 user: stern tags: sxhtml) | |
2023-02-19
| ||
22:59 | Replace sxpf.Pair with new dotted sxpf.List ... (check-in: d0348aed37 user: stern tags: sxhtml) | |
Changes
Changes to shtml/shtml.go.
︙ | ︙ | |||
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | result = result.Cons(te.transformAttrbute(sexpr.GetAttributes(attrList))) } } return result.Cons(te.make("hr")) }) te.bind(sexpr.NameSymListOrdered, 0, te.makeListFn("ol")) te.bind(sexpr.NameSymListUnordered, 0, te.makeListFn("ul")) } func (te *transformEnv) makeListFn(tag string) specialFn { sym := te.make(tag) return func(args *sxpf.List) sxpf.Value { result := sxpf.Nil().Cons(sym) last := result for elem := args; elem != nil; elem = elem.Tail() { item := sxpf.Nil().Cons(te.make("li")) if res, ok := te.evaluate(elem.Car()).(*sxpf.List); ok { item.ExtendBang(res) } last = last.AppendBang(item) } return result } } func (te *transformEnv) bindInlines() { te.bind(sexpr.NameSymInline, 0, func(args *sxpf.List) sxpf.Value { return te.evaluateList(args) }) te.bind(sexpr.NameSymText, 1, func(args *sxpf.List) sxpf.Value { return te.getString(args) }) | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | result = result.Cons(te.transformAttrbute(sexpr.GetAttributes(attrList))) } } return result.Cons(te.make("hr")) }) te.bind(sexpr.NameSymListOrdered, 0, te.makeListFn("ol")) te.bind(sexpr.NameSymListUnordered, 0, te.makeListFn("ul")) te.bind(sexpr.NameSymDescription, 0, func(args *sxpf.List) sxpf.Value { if args == nil { return sxpf.Nil() } items := sxpf.Nil().Cons(te.make("dl")) curItem := items for elem := args; elem != nil; elem = elem.Tail() { term, ok := te.evaluate(te.getList(elem)).(*sxpf.List) if !ok { break } curItem = curItem.AppendBang(term.Cons(te.make("dt"))) elem = elem.Tail() if elem == nil { break } ddBlock := te.getList(elem) if ddBlock == nil { break } // TODO: assert ddBlock.Head() == symBlock for ddlst := ddBlock.Tail(); ddlst != nil; ddlst = ddlst.Tail() { dditem := te.getList(ddlst) descr, ok2 := te.evaluate(dditem).(*sxpf.List) if !ok2 { continue } curItem = curItem.AppendBang(descr.Cons(te.make("dd"))) } } return items }) te.bind(sexpr.NameSymTable, 1, func(args *sxpf.List) sxpf.Value { thead := sxpf.Nil() if header := te.getList(args); header != nil { thead = sxpf.Nil().Cons(te.transformTableRow(header)).Cons(te.make("thead")) } tbody := sxpf.Nil() if argBody := args.Tail(); argBody != nil { tbody = sxpf.Nil().Cons(te.make("tbody")) curBody := tbody for row := argBody; row != nil; row = row.Tail() { curBody = curBody.AppendBang(te.transformTableRow(te.getList(row))) } } table := sxpf.Nil() if tbody != nil { table = table.Cons(tbody) } if thead != nil { table = table.Cons(thead) } if table == nil { return sxpf.Nil() } return table.Cons(te.make("table")) }) te.bind(sexpr.NameSymCell, 0, te.makeCellFn("")) te.bind(sexpr.NameSymCellCenter, 0, te.makeCellFn("center")) te.bind(sexpr.NameSymCellLeft, 0, te.makeCellFn("left")) te.bind(sexpr.NameSymCellRight, 0, te.makeCellFn("right")) te.bind(sexpr.NameSymVerbatimComment, 1, func(args *sxpf.List) sxpf.Value { if te.getAttributes(args).HasDefault() { if s := te.getString(args.Tail()); s != "" { t := sxpf.MakeString("\n" + s.String() + "\n") return sxpf.Nil().Cons(t).Cons(te.make("@@")) } } return nil }) te.bind(sexpr.NameSymVerbatimHTML, 2, te.transformHTML) } func (te *transformEnv) makeListFn(tag string) specialFn { sym := te.make(tag) return func(args *sxpf.List) sxpf.Value { result := sxpf.Nil().Cons(sym) last := result for elem := args; elem != nil; elem = elem.Tail() { item := sxpf.Nil().Cons(te.make("li")) if res, ok := te.evaluate(elem.Car()).(*sxpf.List); ok { item.ExtendBang(res) } last = last.AppendBang(item) } return result } } func (te *transformEnv) transformTableRow(cells *sxpf.List) *sxpf.List { row := sxpf.Nil().Cons(te.make("tr")) if cells == nil { return sxpf.Nil() } curRow := row for cell := cells.Tail(); cell != nil; cell = cell.Tail() { curRow = curRow.AppendBang(te.evaluate(cell.Car())) } return row } func (te *transformEnv) makeCellFn(align string) specialFn { return func(args *sxpf.List) sxpf.Value { tdata := te.evaluateList(args) if align != "" { tdata = tdata.Cons(te.transformAttrbute(attrs.Attributes{"class": align})) } return tdata.Cons(te.make("td")) } } func (te *transformEnv) bindInlines() { te.bind(sexpr.NameSymInline, 0, func(args *sxpf.List) sxpf.Value { return te.evaluateList(args) }) te.bind(sexpr.NameSymText, 1, func(args *sxpf.List) sxpf.Value { return te.getString(args) }) |
︙ | ︙ |