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

<pre> tag does not preserve neither \n nor \t #1261

Closed
maciejjankowski opened this issue Oct 8, 2015 · 7 comments
Closed

<pre> tag does not preserve neither \n nor \t #1261

maciejjankowski opened this issue Oct 8, 2015 · 7 comments
Assignees
Labels

Comments

@maciejjankowski
Copy link

  <script src="https://cdn.jsdelivr.net/g/riot@2.2(riot.min.js+compiler.min.js)"></script>
  <script type="riot/tag">
  <my-tag>
<pre>xyz
  cc
    ss</pre>

  </my-tag>
  </script>
  <my-tag></my-tag>
  <script>
    riot.settings.brackets = '{{ }}';    
    riot.mount("my-tag");
  </script>

http://jsbin.com/yeyoro/edit?html,output

@rsbondi
Copy link
Contributor

rsbondi commented Oct 8, 2015

@aMarCruz will this be handled with your compiler updates?

compiled to

riot.tag('my-tag', '<pre> xyz cc ss </pre>', function(opts) {


});

@rsbondi rsbondi added the bug label Oct 8, 2015
@aMarCruz
Copy link
Contributor

Sorry @maciejjankowski , @rsbondi , I think no.
It would have to scan the entire content. A browser requires hundreds of lines to do just that.
But you can use expressions:

<pre>{ mytext }</pre>
...
this.mytext = [
  'xyz',
  '  cc',
  '    ss'
].join('\n')

Drawback is performance, the expression is evaluated and the element updated with others.
Maybe in the future riot give us expression for one-time evaluation and replace (think about your fix to type=number).

EDIT:
I think, spacing inside quoted strings is not preserved, too. I need check this.

@aMarCruz aMarCruz self-assigned this Oct 10, 2015
@aMarCruz
Copy link
Contributor

Sorry @maciejjankowski , @rsbondi , my fail. The --whitespace option preserves newlines and tabs. You can use this option with the cli, riot.compile have no way to pass options, I'll try to add this feature.

@rsbondi , sorry el inglés no es lo mío :).. el método riot.compile está ya muy sobrecargado para permitir opciones del compilador en el navegador, así que pensando en alternativas...

  1. Un atributo en <script>. @GianlucaGuarini está preparando soporte a opciones adicionales para los parsers por medio del atributo options en <style> y <script>, así que el nombre options ya está "ocupado", se tendría que usar otro como por ejemplo compile (más por aprender para el usuario). Además, el formato debe ser utilizable por JSON.parse (comillas dobles en los nombres de las propiedades). Ventaja de esta solución es que permite diferentes opciones en bloques individuales:

      <script type="riot/tag" compile='{ "whitespace": true }'>
        <my-tag>
      <pre>xyz
          cc
              ss</pre>
       </my-tag>
      </script>
    
  2. Opciones en riot.settings. Esto es más sencillo para el usuario y no sobrecarga el archivo .tag, pero no permite opciones a bloques individuales.

¿Qué me recomiendas?

@rsbondi
Copy link
Contributor

rsbondi commented Nov 15, 2015

Summary:
riot.compile too complicated to implement adding options in the function client side
option 1: adding options as attribute to the script tag, see code above, values for compile would need to be valid JSON.
option 2: add compiler settings to riot.settings, easy for the user but will be global to all blocks so less granular.

I think the global riot-settings is fine, the only downside I see to having all tags with the whitespace option would be the size of the compiled code, which I don't suspect would be a concern, if it is an issue, you should probably be pre-compiling the tags anyway.

@aMarCruz
Copy link
Contributor

@rsbondi , you're right, but since option 1 is consistent with the new optionsattr for parsers, I will include support for this one. Thanks

@aMarCruz
Copy link
Contributor

I just push in the dev branch of riot-compiler a new version which supports preserving whitespace in <pre> tags. This version gets rid of the zero-indentation restriction for custom tags. There's some notes in the CHANGELOG file.

@GianlucaGuarini
Copy link
Member

this issue was fixed in riot 2.3.11

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

No branches or pull requests

4 participants