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

Respect of the formatting of the template (line breaks, spacing...) #29

Open
FALLAI-Denis opened this issue Feb 4, 2021 · 6 comments
Open

Comments

@FALLAI-Denis
Copy link

FALLAI-Denis commented Feb 4, 2021

We plan to use Handlebars to generate program source codes from template, (so template and result are plain text, not html).
The preview should respect the formatting of the template:

  • on line breaks
  • on spacings

Also see if it would be possible to save the preview to keep the result.

See simulation of the expected result by adding <pre> </pre> tags to the template:

hbs_preview_002

hbs_preview_001

@utillity
Copy link

utillity commented Oct 4, 2021

yeah, would be great! Other preview engines detect type or go by extended file-extension (ie. .html.hbs/ .md.hbs. etc)

@johnknoop
Copy link
Owner

Hi @FALLAI-Denis and sorry for the late response. I didn't see this issue until I got an e-mail notification yesterday when @utillity commented on it.

The extension is using a createWebviewPanel to render the preview, which assumes that the content is HTML (which is why all white space get collapsed).

I suppose it would be possible to wrap a pre tag around the file contents, IF we can safely determine that the file is not intended to be rendered as HTML. Perhaps the MyTemplate.csharp.hbs strategy could be one way, although I'm not sure I can come up with a bulletproof way to determine that a template is meant to be rendered as plain text by looking at the filename alone. For example, what if someone has a HTML template named "my.little.page.about.csharp.hbs". It would be a breaking change if we suddenly stopped rendering that as HTML. But I'm open to suggestions if you can formalize a rule that doesn't cause problems for existing users.

@utillity
Copy link

utillity commented Oct 5, 2021

Good point! I would say just make is a setting to "auto-detect" based on filename, or based on first 50 characters containing "<html" or something

@FALLAI-Denis
Copy link
Author

FALLAI-Denis commented Oct 5, 2021

Thanks @johnknoop

The rendering could be determined by the content after transformation:

  • if the first text is <html> then render html as a web page
  • otherwise rendered plain text "as is"

The rendering could also be determined by the command activated to produce the transform:

  • render as web page (and open result in a WebViewPanel)
  • render as text file (and open result in an Editor)

This second solution is therefore not linked to the content, but to the choice of the user.

In the case of plain text rendering, I suggest the result to feed a classic editor rather than a WebViewPanel, (even for html text).
This would allow the file produced by the transformation to be saved, (or edit, and syntax colorized after affecting a Language Mode).

@utillity
Copy link

utillity commented Oct 5, 2021

good point - I like latter one the most :)

@angularsen
Copy link

Bump for visibility 😊

My thoughts:

  • Add separate commands for HTML and plain text, would probably cover most needs.
  • Nice to have: Main command auto-detects html, markdown, etc.
  • Idea: Not sure how, but another plugin I tested a long time ago for Scriban/Liquid showed the raw rendered text (HTML) in one panel, then I could use any plugin of choice to open a preview of that panel. So 3 panels, template => rendered text/HTML => preview of HTML. It seemed like a flexible approach, but the disadvantage was that it required 3 panels instead of just 2.

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

4 participants