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

Glow truncates code; output incomplete #463

Open
maurice opened this issue Jan 26, 2025 · 4 comments · May be fixed by #465
Open

Glow truncates code; output incomplete #463

maurice opened this issue Jan 26, 2025 · 4 comments · May be fixed by #465
Labels
bug nue-glow Related to nue-glow package

Comments

@maurice
Copy link

maurice commented Jan 26, 2025

Describe the Bug

Glow truncates code; output is incomplete.

import { glow } from 'nue-glow';

const code = `const machine = defineMachine<State, Event>({
  states: {
    [stateName]: {
      on: {
        [EVENT_NAME]: { 
          to: 'nextStateName',
          /* ... other options ... */ 
        },
        // ...
      },
    },
    // ...
  },
});
`;

const html = glow(code, { language: 'typescript', numbered: true });

console.info(html);

const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML = `<pre>${html}</pre>`;

Rendered output is

const machine = defineMachine<State, Event>({
  states: {
    [stateName]: {
      on: {
        [EVENT_NAME]: { 
          to: 'nextStateName',

Live demo: https://stackblitz.com/edit/typescript-playground-tenktfl9?file=index.ts

Environment

Web, node

"nue-glow": "^0.2.2"

Minimal Reproduction

As above

Logs & Additional Context

@maurice maurice added the bug label Jan 26, 2025
@nobkd nobkd added the nue-glow Related to nue-glow package label Jan 27, 2025
@nobkd
Copy link
Collaborator

nobkd commented Jan 27, 2025

Seems like /* breaks it.

@nobkd
Copy link
Collaborator

nobkd commented Jan 27, 2025

Update: the space after */ breaks it:

const COMMENT = [/(\/\*|^ *{# |<!--|'''|=begin)/, /(\*\/|#}|-->|'''|=end)$/]

Because of the $, matches only if on end of line.
By removing the $, the whole line gets parsed as comment, and content after */ is also handled as comment.
So this needs some more handling.

Also, if comment is not ended, it should still comment the code until the end.

@tipiirai
Copy link
Contributor

Nicely spotted @nobkd — clearly needs a fix.

@maurice
Copy link
Author

maurice commented Jan 27, 2025

In the initial example I could probably just remove the whitespace after */. But here's another example where I wouldn't want to do that

import { glow } from 'nue-glow';

const code = `const machine = defineMachine<State, Event>({
  // ...
  on {
    [EVENT_NAME]: { 
      data: ({ state, event }) => ({ ...state, /* ... */ }),
    },
  },
});
`;

const html = glow(code, { language: 'typescript', numbered: true });

console.info(html);

const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML = `<pre>${html}</pre>`;

Renders

const machine = defineMachine<State, Event>({
  // ...
  on {
    [EVENT_NAME]: 

@maurice maurice linked a pull request Jan 27, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug nue-glow Related to nue-glow package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants