Platform
Resources
Pricing
Sign in
Get started
Mike Bostock
Visualization toolmaker. Founder @observablehq. Creator @d3. Former @nytgraphics. Pronounced BOSS-tock.
Workspace
Fork
Published
By
Mike Bostock
Edited
Mar 11, 2021
Importers
2 stars
Insert cell
Insert cell
tweet
`Hello, world! #twitter`
Insert cell
Insert cell
function
tweet
(
)
{
const
string
=
String
.
raw
.
apply
(
this
,
arguments
)
.
trim
(
)
;
const
length
=
twitter
.
parseTweet
(
string
)
.
weightedLength
;
return
html
`<div style="font-family: var(--sans-serif);">
<p style="white-space: pre-wrap; min-height: 25px;">${
twitter
.
autoLink
(
string
,
{
usernameIncludeSymbol
:
true
}
)
}</p>
<p style="margin-top: -1em; font-size: 12px; color: ${
length
<=
280
?
"#999"
:
"#e7040f"
};">${
length
} of 280 characters</p>
</div>`
;
}
Insert cell
twitter
=
require
(
"twitter-text@3.0/dist/twitter-text.js"
)
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tweet
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
twitter
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML