/* Package jsx allows you to render blocks of HTML as myitcv.io/react elements. It is a temporary runtime solution for what will become a compile-time transpilation, much like JSX's relationship with Javascript. For more information see https://github.com/myitcv/react/wiki */ package jsx import ( "fmt" "strings" "myitcv.io/react" "github.com/russross/blackfriday" "golang.org/x/net/html" "golang.org/x/net/html/atom" ) // each of the parse* functions does zero validation // this is intentional because everything is expected to // go via the generic parse function // TODO code generate these parse functions func parseP(n *html.Node) *react.PElem { var kids []react.Element // TODO attributes for c := n.FirstChild; c != nil; c = c.NextSibling { kids = append(kids, parse(c)) } return react.P(nil, kids...) } func parseHr(n *html.Node) *react.HrElem { // TODO attributes return react.Hr(nil) } func parseBr(n *html.Node) *react.BrElem { // TODO attributes return react.Br(nil) } func parseH1(n *html.Node) *react.H1Elem { var kids []react.Element // TODO attributes for c := n.FirstChild; c != nil; c = c.NextSibling { kids = append(kids, parse(c)) } return react.H1(nil, kids...) } func parseSpan(n *html.Node) *react.SpanElem { var kids []react.Element var vp *react.SpanProps if len(n.Attr) > 0 { vp = new(react.SpanProps) for _, a := range n.Attr { switch a.Key { case "classname": vp.ClassName = a.Val case "style": vp.Style = parseCSS(a.Val) default: panic(fmt.Errorf("don't know how to handle attribute %q", a.Key)) } } } for c := n.FirstChild; c != nil; c = c.NextSibling { kids = append(kids, parse(c)) } return react.Span(vp, kids...) } func parseI(n *html.Node) *react.IElem { var kids []react.Element var vp *react.IProps if len(n.Attr) > 0 { vp = new(react.IProps) for _, a := range n.Attr { switch a.Key { case "id": vp.ID = a.Val case "classname": vp.ClassName = a.Val default: panic(fmt.Errorf("don't know how to handle attribute %q", a.Key)) } } } for c := n.FirstChild; c != nil; c = c.NextSibling { kids = append(kids, parse(c)) } return react.I(vp, kids...) } func parseFooter(n *html.Node) *react.FooterElem { var kids []react.Element var vp *react.FooterProps if len(n.Attr) > 0 { vp = new(react.FooterProps) for _, a := range n.Attr { switch a.Key { case "id": vp.ID = a.Val case "classname": vp.ClassName = a.Val default: panic(fmt.Errorf("don't know how to handle