this post was submitted on 27 Jul 2024
2 points (100.0% liked)

Perchance - Create a Random Text Generator

448 readers
17 users here now

⚄︎ Perchance

This is a Lemmy Community for perchance.org, a platform for sharing and creating random text generators.

Feel free to ask for help, share your generators, and start friendly discussions at your leisure :)

This community is mainly for discussions between those who are building generators. For discussions about using generators, especially the popular AI ones, the community-led Casual Perchance forum is likely a more appropriate venue.

See this post for the Complete Guide to Posting Here on the Community!

Rules

1. Please follow the Lemmy.World instance rules.

2. Be kind and friendly.

  • Please be kind to others on this community (and also in general), and remember that for many people Perchance is their first experience with coding. We have members for whom English is not their first language, so please be take that into account too :)

3. Be thankful to those who try to help you.

  • If you ask a question and someone has made a effort to help you out, please remember to be thankful! Even if they don't manage to help you solve your problem - remember that they're spending time out of their day to try to help a stranger :)

4. Only post about stuff related to perchance.

  • Please only post about perchance related stuff like generators on it, bugs, and the site.

5. Refrain from requesting Prompts for the AI Tools.

  • We would like to ask to refrain from posting here needing help specifically with prompting/achieving certain results with the AI plugins (text-to-image-plugin and ai-text-plugin) e.g. "What is the good prompt for X?", "How to achieve X with Y generator?"
  • See Perchance AI FAQ for FAQ about the AI tools.
  • You can ask for help with prompting at the 'sister' community Casual Perchance, which is for more casual discussions.
  • We will still be helping/answering questions about the plugins as long as it is related to building generators with them.

6. Search through the Community Before Posting.

  • Please Search through the Community Posts here (and on Reddit) before posting to see if what you will post has similar post/already been posted.

founded 1 year ago
MODERATORS
 

Or .escaped or .plain or whatever you want to call it.

Currently, because string is automatically evaluated, [code] and {options} are processed too. This is pretty annoying if that string is meant to be returned and put into the HTML as-is, not evaluated at all. So I have to find-replace [, ], {, and } characters to escape them all manually.

This could be done with a .raw property on strings, for example--to make it easier for creators to do this. (I'm guessing this would be a fairly common things people need to do, when working on non-trivial plugins, etc.)

you are viewing a single comment's thread
view the rest of the comments
[–] perchance 2 points 3 months ago* (last edited 3 months ago) (1 children)

It's a good request. I agree that the current situation isn't ideal. I'd have to dive into old code to see whether this is hard or easy to implement (i.e. whether 'raw'/original string is already "threaded through" to where it's needed for this to be implemented easily). Something similar to your question here also happens to be mentioned on perchance.org/known-bugs and the workaround that I mention there (and regularly use myself) is to just use functions whenever I want to be sure I'm working with 'raw' stuff i.e. this:

foo() => return "hi {1|2|3}"

instead of:

foo = ["hi {1|2|3}"]

for example.

[–] wthit56 1 points 3 months ago (1 children)

Thing is, I was returning a string from a function in the first place. But to a [code block] in HTML. Maybe that was the issue? In the end I just used a function that took the string and escaped the special characters, and returned that. So, should be possible with a simple getter that does that maybe?

[–] perchance 1 points 3 months ago (1 children)

Oh right, yes, square blocks will always evaluate the text before returning it, so a string.raw type thing wouldn't help with this IIUC. Here's a tested/robust plugin for escaping in case it's helpful: perchance.org/literal-plugin

[–] wthit56 1 points 3 months ago (1 children)

Okay I don't think I'm being clear here... Look at this test: https://perchance.org/test-return-string-or-plain-string-89987987#edit

Two functions are called from HTML code blocks. One returns a string with special characters and it is evaluated and those characters are no longer shown. The other returns the same string, but with special characters escaped by a plain_text() function beforehand. Because the special characters are escaped, they are not parsed by the engine and show as normal regular text, just with those escaping slashes removed.

So you can use that kind of function to spit out untouched HTML. And such a function could be built-in to the engine fairly easily.

[–] perchance 1 points 3 months ago (1 children)

And such a function could be built-in to the engine fairly easily.

Yep, something like perchance.org/literal-plugin could definitely be built in - it's a fair request. I thought you were asking for something different (i.e. stop the actual evaluation at some point in the engine vs just escaping it), though I'm not sure if my original interpretation even makes sense, or wouldn't just be equivalent to escaping right before output to HTML anyway.

[–] wthit56 1 points 3 months ago

Yeah skipping processing for a given string would be ideal, but I know it's super deeply integrated into everything currently. Just the escaping getter is all 👍