Skip to content

added url(translator) support for <paragraph>#304

Open
coderofsalvation wants to merge 1 commit intojbaicoianu:masterfrom
coderofsalvation:feat/paragraph-url-support
Open

added url(translator) support for <paragraph>#304
coderofsalvation wants to merge 1 commit intojbaicoianu:masterfrom
coderofsalvation:feat/paragraph-url-support

Conversation

@coderofsalvation
Copy link
Copy Markdown
Contributor

@coderofsalvation coderofsalvation commented Feb 12, 2026

Ok, honestly this is something I'm pretty excited about:

as discussed earlier, this adds (cached) url-support for <paragraph> via translators:

video-10.mp4

click here for the JML-source of video

First I had hardcoded HTML-urlsupport only..
But then I realized we might want to introduce the beloved 'translator'-concept here as well..
This maximizes the potential of pulling in content from various ecosystems/protocols.
Her's a demo of an custom translator: https://codeberg.org/coderofsalvation/janus-script-activitypub

<paragraph> comes with a default (XML) translator, so janusweb can handle RSS/XML/HTML urls out of the box.
It can also even translate itself! (room.fullsource)

The source-header explains all the possibilities:

 * <paragraph> text-to-texture translator. The builtin XMLtranslator allows:                                                                            
 *                                                
 *  1. inline html             : <paragraph><![CDATA[ <b>hello world</b> ]]></paragraph>
 *  2. inline html (partial)   : <paragraph selector="span"><![CDATA[ <b>hello <span>world</span></b> ]]></paragraph>
 *  3. external url            : <paragraph url="https://janusxr.org"/>
 *  4. external url (partials) : <paragraph url="https://janusxr.org" selector=".infoText"/>
 *  5. janusroom container html: <paragraph selector=".someclass"/>
 *  6. janusroom container xml : <paragraph selector="tag subtag title"/>
 *  7. RSS                     : <paragraph url="https://my.org/foo.rss" selector="item description"/>
 *  8. XML                     : <paragraph url="https://my.org/bar.xml" selector="title"/>
 *  9. any data- or selector-format via 'paragraph_translator' event                             
 *                                                                                                
 *  NOTES:                               
 *  1. By default, selectors are done via `document.querySelectorAll`
 *  2. in case of multiple results:                   
 *    2.1 clicking the paragraph with cycle through them
 *    2.2 setting cycle="2000" allows for (2sec per item) slideshows                       
 *    2.3 setting `rooms.objects.myparagraph.index++` cycles to next item
 *  3. width/height-attributes offers finer control of texture size
 *  4. ttl-attributes allows finer control of webrequest-cache (default 2 mins)
 *  5. setting `rooms.object.myparagraph.selector = "#section2"' allows for statemanagement  

custom translators

Whenever a <paragraph> fetch/renders itself, the room will emit an paragraph_translator event, with (a copy) of the default translator

room.addEventListener("paragraph_translator", function(e){
  const {translator,paragraph} = e.detail
  // now you can override the default translator
  translator.fetch       = async (url) => this.text = "a response"  // my custom fetch function
  translator.translate = () => this.html = this.text                // my x2html translator
}

@coderofsalvation coderofsalvation force-pushed the feat/paragraph-url-support branch from 9a0e182 to 5e5df69 Compare February 12, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant