Skip to content

Commit

Permalink
add new code theme and highlight ability
Browse files Browse the repository at this point in the history
  • Loading branch information
amozoss committed Aug 22, 2023
1 parent 466d603 commit 8c71a21
Show file tree
Hide file tree
Showing 3 changed files with 673 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/dcs/code/rails-activestorage/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ end

Edit `app/views/names/_form.html.erb` to include a `field_field` to allow the user to choose a file to upload

```html
```erb
<div><%= form.label :main_image %> <%= form.file_field :main_image %></div>
```

Expand All @@ -114,9 +114,10 @@ Click "Create Name"&#x20;

Edit `app/views/names/show.html.erb` to include `<%= image_tag @name.main_image %>` to display the image

```html
```erb
<p style="color: green"><%= notice %></p>
<%# highlight %>
<%= render @name %> <%= image_tag @name.main_image %>
<div>
Expand Down Expand Up @@ -155,7 +156,7 @@ ActiveStorage.start()

Modify `app/views/names/_form.html.erb` `form.file_field` to include `direct_upload: true`&#x20;

```html
```erb
<div>
<%= form.label :main_image %> <%= form.file_field :main_image, direct_upload:
true %>
Expand Down
14 changes: 11 additions & 3 deletions src/components/Fence.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { extractAnnotations } from '@code-hike/lighter'
import CodeCopy from '@/components/CodeCopy'
import { convertDocId } from '@/markdoc/convertDocId'

// TODO make a storj theme for now this theme just changes the background color
// https://themes.codehike.org/editor
import light from '@/components/codeTheme.json'
import light from '@/components/storjCodeTheme.json'
let dark = structuredClone(light)
dark.colors['editor.background'] = '#182234'
Code.theme = {
Expand Down Expand Up @@ -51,6 +50,15 @@ const link = {
},
}

export const highlight = {
name: 'highlight',
MultilineAnnotation: ({ children }) => {
return (
<span className="block bg-storj-blue-700 bg-opacity-50">{children}</span>
)
},
}

export const unfocusInline = {
name: 'terminal',
MultilineAnnotation: ({ children }) => {
Expand Down Expand Up @@ -138,7 +146,7 @@ export default async function Fence({ language, children: code, copy = true }) {
} else if (!language || language === 'none') {
language = 'text'
}
let extensions = [link, focus, unfocusInline]
let extensions = [link, focus, unfocusInline, highlight]
const extensionNames = extensions.map((e) => e.name)
let { code: newCode, annotations } = await extractAnnotations(
code.trim() || '',
Expand Down
Loading

0 comments on commit 8c71a21

Please sign in to comment.