Comments (5)
We want them to behave the same here.
from gleam.
So I had a look into this, and it looks like this is due to the difference in behaviour between the string.split_right
implementation between erlang and javascript. The test(s) in question use unicode spaces (U+00A0), and the erlang implementation will keep the space, whereas the javascript version will strip it.
The relevant code is in the following function:
// jot.gleam
fn inlines_to_html(html: String, inlines: List(Inline), refs: Refs) -> String {
case inlines {
[] -> html
[inline, ..rest] -> {
html
|> inline_to_html(inline, refs)
|> inlines_to_html(rest, refs)
|> string.trim_right
}
}
}
If we look at the bad test, with javascript we go from
"<p><em> a "
to
"<p><em> a"
whereas in erlang we keep the space.
I'm not sure what the desired behaviour is here though in order to fix it.
Erlang REPL:
❯ erl
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]
Eshell V14.2.5 (press Ctrl+G to abort, type help(). for help)
1> string:trim("<p><em> a ", trailing).
"<p><em> a "
Node REPL:
❯ node
Welcome to Node.js v18.12.1.
Type ".help" for more information.
> "<p><em> a ".trimRight()
'<p><em> a'
from gleam.
Good detective work! That is a rather annoying difference. 🤔
from gleam.
Yeah definitely not ideal. I'm not sure how/if we would want to resolve this difference. Is there precedence elsewhere in the standard library where there is/was different behaviour between JS and Erlang?
from gleam.
In that case I have created a PR to rework the javascript behaviour to match the erlang behaviour.
from gleam.
Related Issues (20)
- Say "I was not expecting this keyword" in error when there is an unexpected keyword HOT 4
- Bit array int & float options on JavaScript HOT 1
- Compiler panics when a custom type variant doesn't exist HOT 2
- LSP: Inlay hints for multiline pipelines HOT 1
- Imports renamed with `as` then used in consts generate invalid JavaScript code HOT 1
- LSP code action: fill case arms HOT 2
- LSP: narrow complete suggestions after a pipe HOT 1
- LSP: Suggestion on record accessors HOT 2
- LSP: Crash on type redefine HOT 4
- "Else" type variant causes erlang troubles HOT 1
- Option to suppress gleam cli's log messages HOT 1
- Certain code causes a function to not be generated even after passing type checking HOT 2
- LSP Code Action: Convert function callback into `use` statement HOT 1
- False negative diagnostic for unused (aliased) imports HOT 3
- LSP Code Action: Desugar `use` expression
- Invalid Erlang generated with shadowed variables in bit patterns
- Compile error on Windows HOT 3
- Consider adding a flag to the formatter to force an output produced by a specific version HOT 3
- LSP: Show auto-complete types instead of the module names HOT 1
- 'Expected one of : "}" a record constructor' -- Error message improvement for custom types HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gleam.