Inline Markup

Hej,

I’ve read about new feature in Haxe 4 : Inline Markup, but I don’t really understand how to use it.
When I simply write var html = <div>Foo</div>; just to avoid messing with simple and double quotes, I get this error : Markup literals must be processed by a macro.

Can anyone explain me more please ?
Thanks in advance

I’d be interested to know about a status of dsl. There is a discussion ([RFC] XML DSLs · Issue #60 · HaxeFoundation/haxe-evolution · GitHub) but there is no any decision about it.

It may just be one of those things that takes a while to arrive at a really excellent solution.

As I understand inline markup, it’s just an xml-like expression with @:markup meta that you should process with a macro:

static public function markupProcessor(e:Expr) {
    switch e {
      case macro @:markup $v: 
          trace(v);
      default:
    }
    return macro null;
}
...
markupProcessor(<div>Content</div>);
1 Like

Thanks Alexander for your answer.
Yes I’ve seen that but why for example can’t we use markup literals without a macro ? Here compiler catches that <div> is unterminated : Unterminated markup literal. I think it could be also taken as is without be processed by a macro and if one want to process it, it could. Or maybe have a generic macro process function in haxe.Xml for example ? I don’t know…

class Test {
  static function main() {
    var s = markupProcessor( <div>Hello</di> );
    trace( s );
  }
  
  static public macro function markupProcessor(e:haxe.macro.Expr) {
    switch e {
      case macro @:markup $v: 
          return macro $v;
      default:
    }
    return macro null;
  }
}

I think it’s been implemented like a root node should be a valid xml node.