Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Attributes #5

Closed
skipjack opened this issue Dec 3, 2018 · 3 comments
Closed

Single Attributes #5

skipjack opened this issue Dec 3, 2018 · 3 comments
Labels
question Further information is requested

Comments

@skipjack
Copy link
Contributor

skipjack commented Dec 3, 2018

Would you consider handling single attributes like the following:

[quote='username']...[/quote]

I looked around in the presets to see how attributes are handled but didn't see anything that looked like these single attributes (without an explicit field name) are supported or configurable via a preset.

@JiLiZART
Copy link
Owner

JiLiZART commented Dec 9, 2018

Hi @skipjack you can look how parser handle single attributes here https://github.com/JiLiZART/bbob/blob/master/packages/bbob-parser/test/parse.test.js#L69

Also, you can override any tag in preset, for ex

import presetHTML5 from '@bbob/preset-html5';

const getUniqAttr = attrs => Object
  .keys(attrs)
  .reduce((res, key) => (attrs[key] === key ? attrs[key] : null), null);

const myPreset = presetHTML5.extend(tags => ({
  quote: node => ({
    tag: 'blockquote',
    attrs: {
		'data-userid': getUniqAttr(node.attrs)
	},
    content: [{
      tag: 'p',
      attrs: {},
      content: node.content,
    }],
  }),
}))

@JiLiZART JiLiZART added the question Further information is requested label Mar 1, 2019
@skipjack
Copy link
Contributor Author

skipjack commented Jun 27, 2019

Finally started using this library instead of a hacky custom implementation I wrote. I will play around with single attributes and then close this issue.

Related: #6

@skipjack
Copy link
Contributor Author

skipjack commented Jun 28, 2019

Ok I grabbed the getUniqAttr utility from here and used that in combination with an extended preset. I think there are more common bbcode tags but I'll submit a separate PR for that or we can discuss on #28.

Maybe we can expose that utility (e.g. from plugin-helpers) in order for other preset authors and consumers to use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants