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

Added converter for PlantUML builtin functions #409

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ThirtySomething
Copy link

Hi,

as mentionend and proposed in issue #400 this is a substitution mechanism for your extension. In this pull request there is a very quick and dirty draft version as proof of concept. I'm looking forward to your comments and hopefully your support. I'm not so familiar with reqular expressions in TypeScript and how to pass matches (groups) of the find-part to the replace-part. Also I don't know it the place where I've hooked this in is the right place.

Regards

Jochen

@qjebbs
Copy link
Owner

qjebbs commented Jun 14, 2021

Thanks. Basically, you're going to implement a compatible preprocessor within the extension, which I think it not worthwhile to do it. Here is my tips:

  1. execute the preprocessor before the original title processing, since the process may bring in unwanted characters for title
  2. Do replace like following:
    let text = `%lighten("red",20)`;
    let reg = /%([a-z_]+)\((.+?)(?:,(.+?))*\)/ig;
    
    text.replace(reg, (substring, ...args) => {
        let func = substring
        let paras = args.slice(1, args.length - 2)
        console.log(`full: ${substring}}, func: ${func}, paras: ${paras}`)
        switch (func) {
            case "lighten":
                return isDarkPreprocessor(paras[0], paras[1])
            // ...
            default:
                break;
        }
    })
    
    function isDarkPreprocessor(color: String, offset: number): string {
        return "..."
    }

@ThirtySomething
Copy link
Author

Hi,

thanks for your valuable tipps. I've done a complete rewrite of the preprocessor based on your tipps. From my point of view nearly all possible preprocessing is done. There is one point left:

  • Basically I want to use the package ts-expression-evaluator, but I don't know if you agree to this. Additionally I don't know how to set this dependency. Without this package I have to use the Javascript eval function which is basically dangerous. I've marked all relevant code parts with // 001.

Also I've changed the place where I've hooked the preprocessing in. As you mentioned, the preprocessor is called before the title.Deal function.

Regards

Jochen

qjebbs added a commit that referenced this pull request Oct 12, 2021
@qjebbs qjebbs force-pushed the master branch 2 times, most recently from 7194871 to 4a8cef3 Compare March 30, 2024 00:22
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.

2 participants