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

Convert Markdown Command displays "error" notification everytime Settings are modified. #107

Open
pa-0 opened this issue Nov 29, 2024 · 3 comments

Comments

@pa-0
Copy link

pa-0 commented Nov 29, 2024

I have the convert markdown command (part of the 'standard library' -- in this repo) imported into CopyQ and enabled. Whenever I modify settings in the CopyQ app (completely unrelated to this command), as soon as I click Apply, CopyQ displays the following notification:

image

Not sure why, but it definitely seems like a bug (either in the program or in the command). I imported the command from this repository unmodified. And as you can see from the screenshot, it could be anything in Settings that I modify, e.g. the application's appearance/theme. Regardless of what it is, as soon as I click Apply, I get that Markdown Error alert.

@hluk
Copy link
Owner

hluk commented Dec 2, 2024

Can you install the latest version of the app?

Can you also copy the command from Command dialog (F6 shortcut) and paste here for reference?

@pa-0
Copy link
Author

pa-0 commented Dec 7, 2024

I'm on v9.1.0 already.

copyq:
const markdownTag = 'markdown'
const mimeTags = 'application/x-copyq-tags'
const tagFragments = ['@']
const textFragments = [
    '`',
    '\n##',
    '](',
    '\n* ',
]
const errorLabel = 'Markdown Error'

function contains(text, what) {
    return text.indexOf(what) != -1
}

function startsWith(text, what) {
    return what === text.substring(0, what.length)
}

function matchesAnyOf(text, fragments) {
    return fragments.find(e => text.indexOf(e) != -1)
}

function addHtml(html, tag) {
    setData(mimeHtml, html)
    if (tag) {
        tags = data(mimeTags)
        tags = (tags ? str(tags) + ',' : '') + tag
        setData(mimeTags, tags)
    }
    return true
}

function addHtmlOutput(result, tag) {
    if (!result) {
        notification(
            '.id', 'highlight',
            '.message', 'Failed to add syntax highlighting',
        )
        return false
    }

    if (result.exit_code !== 0) {
        popup(errorLabel, result.stderr)
        return false
    }

    return addHtml(result.stdout, tag)
}

function markdown(textData) {
    result = execute('marked', null, textData)
    return addHtmlOutput(result, markdownTag)
}

function highlightCode() {
    var formats = dataFormats()
    if ( formats.indexOf(mimeHidden) != -1
      || formats.indexOf(mimeHtml) != -1 ) {
        return false
    }

    var textData = data(mimeText)
    var text = str(textData)
    if (!text)
        return false

    tags = str(data(mimeTags))

    try {
        if ( startsWith(text, 'http') )
            return markdown(textData, 'md')

        if ( matchesAnyOf(tags, tagFragments)
          || matchesAnyOf(text, textFragments) ) {
            return markdown(textData)
        }
    } catch(e) {
        popup(errorLabel, e)
        serverLog(errorLabel + ': ' + e)
    }

    return false
}

highlightCode()

@hluk
Copy link
Owner

hluk commented Dec 9, 2024

Can you copy the whole command from the command list or with the Copy Selected button? The code should be in ini format starting with [Command].

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

No branches or pull requests

2 participants