Skip to content
New issue

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

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

Already on GitHub? # to your account

Define custom code extractors in settings #1079

Open
bollwyvl opened this issue Apr 19, 2024 · 4 comments · May be fixed by #1080
Open

Define custom code extractors in settings #1079

bollwyvl opened this issue Apr 19, 2024 · 4 comments · May be fixed by #1080

Comments

@bollwyvl
Copy link
Collaborator

Elevator Pitch

Offer an appropriate place in settings to define new extractors via JSON schema.

Motivation

The existing hard-coded extractors are a fairly inflexible way to extend the system.

This would allow a non-TS system to extend

Design Ideas

  • add a mapping of RegExpForeignCodeExtractor.IOptions (plus a rank) to the right plugin's settings schema:
"definitions": {
    "code-extractors": {
        "type": "object",
        "title": "Code Extractors",
        "description": "descriptions of how to find other language blocks, keyed by host language",
        "additionalProperties": {
            "$ref": "#/definitions/host-code-extractors"
        }
    },
    "host-code-extractors": {
        "type": "object",
        "descirption": "code extractors for a single host language, keyed by regular expression",
        "additionalProperties": {
            "$ref": "#/definitions/codeExtractor"
        }
    },
    "code-extractor": {
        "type": "object",
        "properties": {
            "language": {
                "type": "string",
                "description": "the guest language for the code that is extracted"
            },
            "...etc": {}
        }
    }
}

With an example:

    new RegExpForeignCodeExtractor({
      language: 'javascript',
      pattern: '^%%(js|javascript)( .*?)?\n([^]*)',
      foreignCaptureGroups: [3],
      isStandalone: false,
      fileExtension: 'js'
    }),

represented as:

{
    "codeExtractors": {
        "python": {
            "^%%(js|javascript)( .*?)?\n([^]*)": {
                "language": "javascript",
                "foreignCaptureGroups": [3],
                "isStandalone": false,
                "fileExtension": "js",
                "rank": 100
            }
        }
    }
}
  • use mapping at startup time, probably need to handle dynamism
  • move existing hard-coded ones to schema defaults

🏓 @tonyfast

@krassowski
Copy link
Member

Sounds good to me.

@bollwyvl
Copy link
Collaborator Author

Cool. I'll take a look.

Some more musings:

  • could target the core plugin settings
  • could be a/some new plugin(s), which exports an optional token to the core (so they can be disabled, for some reason)

I think the idea would be that some py (but non-js) package could put something in the settings conf.d location and have it "just work," even to replace existing ones.

@krassowski
Copy link
Member

I was thinking that a new plugin would be good to have a new tab in settings too.

@bollwyvl bollwyvl linked a pull request Apr 22, 2024 that will close this issue
7 tasks
@bollwyvl
Copy link
Collaborator Author

Very WIP PR: #1080

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants