Coder Social home page Coder Social logo

Comments (4)

fredemmott avatar fredemmott commented on September 27, 2024

The runtime should actually already be fine with this - it needs xhp library and typechecker extensions though.

From an open source perspective, this would probably need to be a new language feature rather than a .hhconfig option - we definitely don't want to encourage libraries that require .hhconfig changes (or any other project-wide or global setting), but it's workable in a monorepo

from xhp-lib.

Kilenaitor avatar Kilenaitor commented on September 27, 2024

it needs xhp library and typechecker extensions though

Assuming this change would need to be in the HHVM repo, then? e.g. here?

If you have some pointers, I'd be happy to try and contribute to this if I have time. I doubt it's urgent since I'm guessing no one has asked for this before me haha.

Main thing that's still unclear to me is how to actually configure which special attribute prefixes to allow. I'm assuming the "would probably need to be a new language feature" means rather than a config option it'd be some new special syntax for how to declare these (e.g. in addition to attribute something like special-attributes but with an actually-good name). Would still be nice though to have some way to extend/augment the existing XHP HTML elements with these special attributes. Unless the intention is to require reimplementing core elements whenever non-standard attributes are desired. While I'd understand that principle... it'd be a bit annoying haha.

But yeah. As said above, if you have some idea of how this would get done, I'd be down to give it a shot.

from xhp-lib.

lexidor avatar lexidor commented on September 27, 2024

I am very interested in how this would be implemented. I am worried this will make xhp attributes more unsound. data- and aria- are unsound. If the information about which prefixes are special depends on the (base)type, you are left reimplementing the html tags anyway. If this information is dynamically configurable, this would make any attribute string prefix-thing possibly unsound.

Would it be okay if the renderer could be configured to special case prefixes like data-up- to render as up-? So in XHP, you'd write.

<p data-up-expand="JS" />

which would render as <p up-expand="JS"></p>?

protected final function renderBaseAttrs(): string {
$buf = '<'.$this->tagName;
foreach ($this->getAttributes() as $key => $val) {
if ($val !== null && $val !== false) {
if ($val === true) {
$buf .= ' '.\htmlspecialchars($key);
} else {
if ($val is \Facebook\XHP\UnsafeAttributeValue_DEPRECATED) {
$val_str = $val->toHTMLString();
} else {
$val_str = \htmlspecialchars((string)$val, \ENT_COMPAT);
}
$buf .= ' '.\htmlspecialchars($key).'="'.$val_str.'"';
}
}
}
return $buf;
}

Adding an if () {} here would keep type safety equal, at the cost of having to type out data- prefixes.

from xhp-lib.

fredemmott avatar fredemmott commented on September 27, 2024

I think we'd be very unlikely to provide a way to retrofit this to existing HTML classes:

  • it is essentially what the data- attributes are meant for
  • it would make migrating XHP attributes to be class properties much more difficult - we would already have to special-case data- and aria-, but these can be detected just at the callsite. Allowing plugin-extensions here would require looking at parts of the current tree that are not ancestors in the class hierarchy

from xhp-lib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.