Skip to content
Snippets Groups Projects
Select Git revision
  • 4a0e5a3462e4b36b2cd22e3e1711a80f5930dd95
  • master default protected
  • 9.0
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

js_html.pike

Blame
  • XML.pmod 1.45 KiB
    import ".";
    
    string *from=({"&#a0;","&","<",">"});
    string *to=({"","&","<",">"});
    
    string unquote(string x) { return replace(x,from,to); }
    string quote(string x) { return replace(x,to,from); }
    
    string *from_data=({"&#a0;","&amp;","&lt;","&gt;","&apos;","&quot;"});
    string *to_data=({"","&","<",">","'","\""});
    
    string unquote_data(string x) { return replace(x,from_data,to_data); }
    string quote_data(string x) { return replace(x,to_data,from_data); }
    
    #define TAG object(Sgml.Tag)|string
    #define SGML array(TAG)
    
    string mktag(string tag, mapping params, int end)
    {
      string ret="<"+tag;
      foreach(indices(params),string i)
        if(params[i])
          ret+=" "+i+"='"+quote_data(stringp(params[i])?params[i]:i)+"'";
    
      return ret + (end?"/>":">");
    }
    
    string generate(SGML data, void|function mkt)
    {
      string ret="";
      if(!mkt)
      {
        mkt=mktag;
      }
      foreach(data, TAG foo)
        {
          if(stringp(foo))
          {
    	ret+=quote(foo);
          }
          else if (objectp(foo))
          {
    	ret+=mkt(foo->tag,foo->params,!foo->data);
    	if(foo->data)
    	{
    #if 0
    	  if(foo->tag=="script")
    	  {
    	    // Magic for javascript!
    	    ret+="\n<!--\n"+
    	      foo->data*""+
    	      "// -->\n";
    	  }else
    #endif
    	    ret+=generate(foo->data,mkt);
    
    	  ret+=mkt("/"+foo->tag,([]),0);
    	}
          }
          else error("got an illegal tag or string : %O\n"
    		 "in: %O\n",foo,data);
        }
    
      return ret;
    }
    
    
    #ifdef TEST
    int main()
    {
      write(sprintf("%O\n",group(lex(Stdio.read_file("tutorial.wmml")))));
    }
    #endif