Skip to content

Add selection and selectionHtml variables #495

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions docs/Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ Preset variables are automatically generated based on the page content. These ty

The main content variable is `{{content}}`, which contains the article content, or the [[Highlight web pages|highlights]], or the selection if there is any selected text on the page. Note that `{{content}}` attempts to extract the main content of the page, which may not always be what you want. In that case, you can use other preset variables or selector variables to extract the content you need.

| Variable | Description |
| ----------------- | -------------------------------------------------------------------------------------- |
| `{{author}}` | Author of the page |
| `{{content}}` | Article content, [[Highlight web pages\|highlights]], or selection, in Markdown format |
| `{{contentHtml}}` | Article content, [[Highlight web pages\|highlights]], or selection, in HTML format |
| `{{date}}` | Current date, can be formatted using the `date` filter |
| `{{description}}` | Description or excerpt |
| `{{domain}}` | Domain |
| `{{favicon}}` | Favicon URL |
| `{{fullHtml}}` | Unprocessed HTML for the full page content |
| `{{highlights}}` | [[Highlight web pages\|Highlights]] with text and timestamps |
| `{{image}}` | Social share image URL |
| `{{published}}` | Published date, can be formatted using the `date` filter |
| `{{site}}` | Site name or publisher |
| `{{title}}` | Title of the page |
| `{{time}}` | Current date and time |
| `{{url}}` | Current URL |
| `{{words}}` | Word count |
| Variable | Description |
| ------------------- | -------------------------------------------------------------------------------------- |
| `{{author}}` | Author of the page |
| `{{content}}` | Article content, [[Highlight web pages\|highlights]], or selection, in Markdown format |
| `{{contentHtml}}` | Article content, [[Highlight web pages\|highlights]], or selection, in HTML format |
| `{{selection}}` | Selection in Markdown format |
| `{{selectionHtml}}` | Selection in HTML format |
| `{{date}}` | Current date, can be formatted using the `date` filter |
| `{{description}}` | Description or excerpt |
| `{{domain}}` | Domain |
| `{{favicon}}` | Favicon URL |
| `{{fullHtml}}` | Unprocessed HTML for the full page content |
| `{{highlights}}` | [[Highlight web pages\|Highlights]] with text and timestamps |
| `{{image}}` | Social share image URL |
| `{{published}}` | Published date, can be formatted using the `date` filter |
| `{{site}}` | Site name or publisher |
| `{{title}}` | Title of the page |
| `{{time}}` | Current date and time |
| `{{url}}` | Current URL |
| `{{words}}` | Word count |

## Prompt variables

Expand Down
3 changes: 3 additions & 0 deletions src/utils/content-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export async function initializePageContent(
}

const markdownBody = createMarkdownContent(content, currentUrl);
const selectedMarkdown = createMarkdownContent(selectedHtml, currentUrl)

// Convert each highlight to markdown individually and create an object with text, timestamp, and notes (if not empty)
const highlightsData = highlights.map(highlight => {
Expand All @@ -148,6 +149,8 @@ export async function initializePageContent(
'{{author}}': author.trim(),
'{{content}}': markdownBody.trim(),
'{{contentHtml}}': content.trim(),
'{{selection}}': selectedMarkdown.trim(),
'{{selectionHtml}}': selectionHtml.trim(),
'{{date}}': dayjs().format('YYYY-MM-DDTHH:mm:ssZ').trim(),
'{{time}}': dayjs().format('YYYY-MM-DDTHH:mm:ssZ').trim(),
'{{description}}': description.trim(),
Expand Down