Comments (7)
^_^ awesome, ty!
from forem.
I'm hesitant to allow arbitrary styles into the final post because of how easy it would be for publishers to create articles that look bad, especially across platforms and screen sizes and future site-wide design changes.
Under this current system of sanitizing styles, it's the client side preview that is wrong.
But, of course, the style of your post, in that exact format, is not possible. We could implement some custom classes that map to style adjustments. It might even make sense to use known classes from a popular library like bootstrap to dictate this.
from forem.
But, of course, the style of your post, in that exact format, is not possible.
Not sure I understand.
Under this current system of sanitizing styles, it's the client side preview that is wrong.
Given the non-standardness of Markdown, it might make sense to use the same lib for both server-side and client-side rendering, or always delegate to the client, or settle on a given specification such as common markdown (though even that could be fragile).
It might even make sense to use known classes from a popular library like bootstrap to dictate this.
Prob best to avoid anything externally specified, otherwise we couple the content to some version of some CSS framework, and then changing anything becomes difficult (ie all content from all time has to continue working, so if the framework releases a new version that is not backwards compatible, then we have to continue using the old version or perform some error-prone content transformation or record which version to serve with each post)
We could implement some custom classes that map to style adjustments.
That could work. Generally, I'm fine with letting the site control styling, I mostly expect it to do a better job than I will, and that decreases fragility as the site changes over time. In this case, it's not styling I'm trying to change so much as layout. If I had a way to specify this layout, I'd have no need to try manually styling:
Though it's worth noting that I have a sample point of 1 (just me, only one post), so this shouldn't be considered a comprehensive analysis. Eg it could be that I want to do something fancy at some point (Medium accommodates this with "embeds", I haven't explored their flexibility).
FWIW, I do like the idea of tracking the stylesheet with the content, then we could provide users with several stylesheet options, and they could choose the one that best matches their content (eg prose tends to go well with serif fonts, and technical content tends to go best with sans-serif fonts).
Given the site is targeted at devs creating and consuming dev-oriented content, it seems reasonable to expect them to have content whose presentation requires more control. Eg is it possible to write a post like this or this without sacrificing convenience in the common cases?
from forem.
Yeah, right now we use showdown on the client preview and redcarpet on the server. It's been good enough so far, but since this is pretty core to what we're doing it will be a focus to improve this.
That's why our first open source extraction project is around the markdown. Depending on where this conversation goes, may make sense to break things up and discuss in that project space.
Wholeheartedly agree with the idea that devs creating and consuming dev-oriented content can guide a lot of our decisions and assumptions and is why I want to make it possible to build richer content, I still want to ensure we do it safely and steadily and not rush into any assumptions about usability and compatibility.
from forem.
I still have this issue after updating the post to remove all the HTML except a few strong tags (b/c they weren't highlighting correctly in Atom Editor, and that worried me that they were ambiguous, the <strong>
seemed less ambiguous)
Further, when I published it and went to the page, it was displaying only the summary. ie the renderer for published posts is showdown, the incorrect one. Note that when I entere the content into the showdown demo, and it works correctly.
---
title: Write a REPL in Ruby
published: false
description: Lets build a REPL!
cover_image:
tags:
---
[Pry](http://pryrepl.org/), [IRB](http://ruby-doc.org/stdlib-2.3.1/libdoc/irb/rdoc/IRB.html),
and [RIPL](https://rubygems.org/gems/ripl) are popular Ruby REPLs, but, just for funsies,
lets see what it takes to build our own! Code snippets are
[here](https://gist.github.com/JoshCheek/baab86f3258ff98c468f3dbc032dc9c5).
---
Simple beginnings
-----------------
A <strong>REPL</strong> must "<strong>R</strong>ead" input from the user,
"<strong>E</strong>val"uate that input as code, "<strong>P</strong>rint"
the result, and "<strong>L</strong>oop" back to the first step to do it
all over again. So, lets start with those four steps.
![screenshot](https://cdn-images-1.medium.com/max/600/1*qWygoGudYFcFuPVMDUDKFw.png)
---
Persist local variables
-----------------------
The problem with our REPL at present is it forgets local variables đ Thatâs because
local variables are stored in "bindings" on the callstack. When we call `eval`,
it makes a new binding to evaluate the code in, and when `eval` is finished,
it pops that binding off the callstack discarding our variables. To retain the
variables between invocations, we need to evaluate them in the same binding every time.
![screenshot](https://cdn-images-1.medium.com/max/600/1*XxwgW544hDGlwXRTJ17pHQ.png)
---
Readline input
--------------
Our input is... not good đ But, Ruby ships with [`Readline`](https://ruby-doc.org/stdlib-2.3.3/libdoc/readline/rdoc/Readline.html),
which is like `gets`, but adds a prompt, kill ring, fancy movement/editing, cycling through previous inputs, etc.
![animated screenshot](https://cdn-images-1.medium.com/max/600/1*hy59uAXv3wTGRhQMPQ8Eqw.gif)
---
Highlight output
----------------
Looks good, lets syntax highlight our output. [Rouge](https://rubygems.org/gems/rouge)
is the way to go these days, but [CodeRay](https://rubygems.org/gems/coderay)
has a simpler interface. We just pass it through CodeRay between inspecting and printing.
![screenshot](https://cdn-images-1.medium.com/max/600/1*SH_f_Dg9qTCtzNuBcN3mHg.png)
---
Handle EOF
----------
Currently, if we hit the end of the input stream (eg user presses `control-d`),
we explode in `eval`. This is because `input` is `nil`.
Lets stop the loop in this situation.
![screenshot](https://cdn-images-1.medium.com/max/600/1*BuCkA9WP0_gePukpFDM8dA.png)
---
Handle Errors
-------------
It would also be nice to handle errors in the input, so lets rescue and display
them! The `\e[31m` is the [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code)
to turn the foreground red and the `\e[0m` will turn off the red. Note that,
while common, these codes arenât portable.
![screenshot](https://cdn-images-1.medium.com/max/600/1*eAJf1FkG56qilcqkuI-40w.png)
---
Where to go from here?
----------------------
So, in 10 lines of code, weâve constructed a fairly respectable REPL! If you found that fun, try adding some additional functionality:
* Save the previous result in `_` (probably `Binding#local_variable_set`)
* Handle large objects better, eg `{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "sha"+"z"*20+"am"}}}` could get formatted very nicely if, you replace `inspect` with [`pretty_inspect`](http://www.rubydoc.info/stdlib/pp/Kernel#pretty_inspect-instance_method) from `pp.rb`, in the standard library.
* Remember history across invocations (check the [Readline](https://ruby-doc.org/stdlib-2.3.3/libdoc/readline/rdoc/Readline.html) docs)
* Syntax highlight the input (thereâs probably a [Readline](https://ruby-doc.org/stdlib-2.3.3/libdoc/readline/rdoc/Readline.html) method to let you swap it out after itâs been entered)
* Add some commands like pryâs `ls` (search around for a list of reflection methods in order to get the information) and show-source (check these humansâ gems: [bannister](https://rubygems.org/profiles/banister), [ConradIrwin](https://rubygems.org/profiles/ConradIrwin), [ryanf](https://rubygems.org/profiles/ryanf), [kyrylo](https://rubygems.org/profiles/kyrylo))
* Separate the REPLâs variables from the userâs. Enter `local_variables`, and youâll see youâre sharing them with the program. Youâll have to get a binding that doesnât come from that context. Possibly useful: `TOPLEVEL_BINDING`, `eval` on a string, define a method on the singleton class then remove it, `Kernel#load`, and that JavaScript idiom of defining a lambda you immediately call.
* What would it take to make this testable? Youâd probably want to be able to pass it the binding and IO streams. Readline looks plainful, IDK how itâs storing its state, but itâs going to be fragile or broken. Youâll want to segregate it from the rest of your program as much as possible, and if you want 100% coverage, you may need [PTY](http://www.rubydoc.info/stdlib/pty/PTY)s
from forem.
Oh, I just realized what the issue is. Three dashes in Markdown is a <hr>
tag, but that's also what the frontmatter is using as a delimiter. It's probably pulling all the content up to the last ---
as frontmatter (if it were a regex, it's the difference between *
and *?
)
from forem.
@JoshCheek we made some changes on our end to make sure preview & saved posts are the same. I'm closing this but moving your multiple stylesheet suggestion to our private repo for some internal discussion. Thanks for being awesome and giving feedback, we really appreciate it.
from forem.
Related Issues (20)
- \[Honeybadger\] google_oauth2: ActiveRecord::RecordNotUnique (#108660187) HOT 1
- \[Honeybadger\] github: ActiveRecord::RecordInvalid (#100629267) HOT 1
- User flags suppresses post visibility inconsistently and for logged-in users only HOT 1
- GitHub profile picture in liquid tags do not update HOT 1
- Code block horizontal scroll covers code HOT 2
- Can't create account with Apple ID if no name is associated HOT 1
- Individual RSS Feed Issues HOT 1
- \[Honeybadger\] Action not available: NoMethodError (#110492423) HOT 2
- Cannot Fetch API due to CORS error from Forem API HOT 4
- \[Honeybadger\] create: ActiveRecord::RecordNotUnique (#91720189) HOT 1
- Can't flag accounts with DEV++ HOT 2
- "Name not valid" validation error message is not showing when it fails to match, user have to go in network tab to check what is breaking in UI. HOT 1
- Request for Assistance: Decrease in New Users and Unpublished Blogs Due to Security Concerns on Dev.to HOT 3
- Error - Project Setup with Dockerfile HOT 1
- Getting errors for CORS while running on local HOT 2
- Dip & Docker Install Lacks Hypershield Schema HOT 1
- DO YOU NEED A HACKER OR RECOVERY COMPANY TO HELP YOU GET YOUR MONEY BACK FROM SCAMMERS> BRUNOE QUICK HACK HOT 1
- Markdown code in a code block breaks the UI HOT 4
- Commenting on posts leads to cyclic JSON object error HOT 3
- NextJS deployment on IIS Windows Server HOT 1
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 forem.