Skip to content

Add a "SetContent" function#16

Merged
marcellov7 merged 3 commits into
marcellov7:mainfrom
jokogarcia:set-content
Jun 24, 2026
Merged

Add a "SetContent" function#16
marcellov7 merged 3 commits into
marcellov7:mainfrom
jokogarcia:set-content

Conversation

@jokogarcia

Copy link
Copy Markdown

This pull request introduces a new setContent method to the tex library, allowing users to programmatically set the content of the editor. It updates the core library, documentation, and examples to reflect this new functionality.

Core Library Changes:

  • Added a setContent method to the tex object, allowing users to set the content of the editor via JavaScript. This method updates both the visible editor content and the underlying HTML content. (src/tex.js, [1] [2]

Documentation Updates:

  • Updated the README.md to include setContent in the list of exported methods and added an example usage of setContent under a new "Set Content" section. (README.md, [1] [2]

Example Updates:

  • Modified examples/index.html by adding a new editor instance (editor4) and demonstrating the use of the setContent method to populate it with programmatically defined content. (examples/index.html, [1] [2]

@marcellov7 marcellov7 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — approving.

setContent is consistent with the existing getContent pattern, exported correctly (tex object + named export), and documented with a working example. It correctly syncs both the visible .tex-content and the hidden .htmlContent view.

Minor, non-blocking notes for a follow-up:

  • el.value = content is a no-op for <div>-based editors (only meaningful for <textarea> bases) — harmless.
  • The method doesn't fire the onChange callback, so listeners aren't notified of programmatic changes. Would be nice to plumb that through.
  • README example string is missing the closing </p>.

@marcellov7 marcellov7 merged commit 10d5eeb into marcellov7:main Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants