Skip to content

Add ts-graphviz plugin to the remark plugins #15

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

Merged
merged 5 commits into from
Nov 8, 2024

Conversation

kamiazya
Copy link
Member

@kamiazya kamiazya commented Nov 7, 2024

This pull request includes significant updates to the documentation and introduces a new plugin for handling ts-graphviz code blocks in markdown files. The changes improve the way code examples are displayed and enhance the documentation configuration.

Documentation Updates:

  • Renamed docs/ts-graphviz/02-core-features/index.mdx to docs/ts-graphviz/02-core-features/index.md and updated the code block for better readability.
  • Renamed i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.mdx to i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.md and similarly updated the code block.

Configuration Changes:

  • Updated docusaurus.config.ts to include the new tsgraphviz remark plugin for processing ts-graphviz code blocks.

Plugin Introduction:

  • Added a new plugin remark-plugin-tsgraphviz.ts to transform ts-graphviz code blocks into TSGraphvizLiveEditor components, making the code examples interactive and read-only. I have added the ts-graphviz plugin to the remark plugins in order to enable the rendering of graph visualizations in the documentation. This will enhance the user experience and provide better understanding of the code examples.

Summary by CodeRabbit

  • New Features

    • Enhanced documentation for the ts-graphviz library with improved code block formatting for TypeScript examples.
    • Added a new plugin for better handling of Graphviz-related Markdown content.
  • Bug Fixes

    • Removed the deprecated TSGraphvizLiveEditor component to streamline examples.
  • Documentation

    • Updated both English and Japanese documentation to reflect changes in code presentation and usability, ensuring clarity and usability for users.
    • Retained explanations emphasizing TypeScript's strong typing and IntelliSense support.

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes in this pull request involve updates to the documentation and configuration for the ts-graphviz library. The TSGraphvizLiveEditor component has been removed from the documentation, replaced by a read-only code block format for TypeScript examples. Additionally, a new plugin, tsgraphviz, has been added to the Docusaurus configuration to enhance Markdown processing. Documentation updates include similar changes in the Japanese language version. A new plugin file has also been introduced to manage the transformation of TypeScript Graphviz code blocks in the documentation.

Changes

File Path Change Summary
docs/ts-graphviz/02-core-features/index.md Removed <TSGraphvizLiveEditor /> component; introduced read-only code block format for TypeScript examples.
i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.md Similar changes as above for the Japanese documentation, focusing on read-only code blocks.
docusaurus.config.ts Added tsgraphviz plugin to remarkPlugins in the Docusaurus configuration for enhanced Markdown support.
plugins/remark-plugin-tsgraphviz.ts Introduced a new plugin for transforming TypeScript Graphviz code blocks in Markdown; includes several type definitions and functions.
package.json Added new dependencies for Markdown AST processing in devDependencies.

Possibly related PRs

  • Auto resize the editor #12: The changes in this PR involve the TSGraphvizLiveEditor component, which is directly related to the removal of the TSGraphvizLiveEditor component in the main PR's documentation updates. Both PRs focus on enhancing the usability and presentation of the ts-graphviz library's documentation and components.
  • Update to use docusaurus components #13: This PR updates the TSGraphvizLiveEditor component by enhancing its functionality, which is directly related to the changes made in the main PR regarding the removal of the TSGraphvizLiveEditor component and the introduction of new documentation formats.

Suggested labels

enhancement

Poem

🐰 In the garden of code, we hop and play,
With blocks of TypeScript, clear as day.
The live editor's gone, but fear not,
For readability blooms in every plot!
A plugin added, our docs now shine,
Hooray for ts-graphviz, it's simply divine! 🌟

Warning

Tool Failures:

Tool Failure Count:


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between afb1160 and 3f3c92e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • plugins/remark-plugin-tsgraphviz.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/remark-plugin-tsgraphviz.ts
🔇 Additional comments (2)
package.json (2)

50-50: LGTM: Type definitions for AST processing.

The added type definitions (@types/mdast, @types/unist) are appropriate for implementing a remark plugin that processes Markdown AST.

Also applies to: 53-53, 54-54


54-54: LGTM: Core dependencies for Markdown processing.

The added dependencies (mdast-util-mdx-jsx, unified, unist-util-visit) provide the necessary utilities for implementing the ts-graphviz remark plugin. The version constraints using caret (^) align with the project's versioning strategy.

Let's verify the compatibility of these packages with the project's Node.js version requirement:

Also applies to: 57-57, 58-58

✅ Verification successful

Let me try a different approach to verify the Node.js compatibility by checking the package.json files directly from the npm registry.


Dependencies are compatible with project's Node.js requirements

The project requires Node.js >=18.0, and none of the added packages ([email protected], [email protected], [email protected]) specify any conflicting Node.js engine requirements. Since these packages are widely used in the Node.js ecosystem and their latest versions are being used, they are compatible with Node.js 18+. The absence of explicit engine requirements in their package.json suggests they follow Node.js's LTS support policy.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify package compatibility with Node.js >=18.0
# Expected: All packages should list Node.js >=18.0 in their package.json

for pkg in mdast-util-mdx-jsx unified unist-util-visit; do
  echo "Checking $pkg..."
  npm info $pkg engines.node
done

Length of output: 681


Script:

#!/bin/bash
# Get package.json content for each package
for pkg in mdast-util-mdx-jsx unified unist-util-visit; do
  echo "=== $pkg ==="
  npm view $pkg engines --json 2>/dev/null || echo "No engines field specified"
  echo "Version requirements:"
  npm view $pkg version
done

# Also check our project's Node.js requirement
echo -e "\nProject Node.js requirement:"
grep '"node":' package.json || echo "No Node.js requirement specified in package.json"

Length of output: 879


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (6)
i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.md (1)

11-18: LGTM! The new read-only code block format is well-implemented.

The example effectively demonstrates the TypeScript integration and type-safe attribute usage.

Consider adding inline comments to explain the attribute helper usage, as it's a key TypeScript feature. For example:

 import { digraph, attribute as _ } from 'ts-graphviz';
 
 const G = digraph('G', (g) => {
+  // Type-safe attribute access using the attribute helper
   g.node('A', { [_.color]: 'red' });
+  // Edge creation with labeled connection
   g.edge(['A', 'B'], { [_.label]: 'A to B' });
 });
docusaurus.config.ts (2)

35-35: Configuration looks good, consider documenting plugin options.

The plugin configuration is consistently applied across docs, blog, and pages sections. The empty options object suggests default configuration is being used.

Consider adding documentation for available plugin options in the README or plugin documentation.

Also applies to: 44-44, 50-50


5-5: Good architectural decision moving to a plugin-based approach.

The shift from using TSGraphvizLiveEditor component to a remark plugin is a solid architectural choice because it:

  1. Centralizes the transformation logic
  2. Ensures consistent handling across all documentation sections
  3. Follows Docusaurus's recommended patterns for content transformation

Also applies to: 35-35, 44-44, 50-50

plugins/remark-plugin-tsgraphviz.ts (3)

8-8: Define 'PluginOptions' type or remove it if unnecessary

The PluginOptions type is currently an empty object {}. If no options are needed for the plugin, consider removing this type. If options are expected in the future, define them explicitly to enhance code clarity.


89-89: Consider importing 'unist-util-visit' statically

Currently, unist-util-visit is imported dynamically within the plugin function. Unless there's a specific reason for dynamic importing (like code-splitting for performance optimization), consider importing it statically at the top of the file to improve readability and reduce overhead.

Apply the following change to import it statically:

-  return async (root) => {
-    const { visit } = await import('unist-util-visit');
+  import { visit } from 'unist-util-visit';
+
+  return (root) => {

121-121: Update comment to reference the correct module

The comment mentions require('npm2yarn'), which seems unrelated to this plugin. This might be a leftover from a copy-paste. Update the comment to accurately reflect the current module to avoid confusion.

Suggested change:

- // To continue supporting `require('npm2yarn')` without the `.default` ㄟ(▔,▔)ㄏ
+ // To continue supporting `require('remark-plugin-tsgraphviz')` without the `.default` ㄟ(▔,▔)ㄏ
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5b2a0d9 and d3dba50.

📒 Files selected for processing (4)
  • docs/ts-graphviz/02-core-features/index.md (1 hunks)
  • docusaurus.config.ts (3 hunks)
  • i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.md (1 hunks)
  • plugins/remark-plugin-tsgraphviz.ts (1 hunks)
🔇 Additional comments (3)
i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.md (1)

11-18: Verify consistent handling of code blocks across documentation.

The new ts-graphviz:read-only tag is used in the first example but not in subsequent code blocks. Let's verify the plugin handles both cases correctly.

[^\n]ts-graphviz[^\n]\n[\s\S]*?```" --type md

Test 2: Specifically find read-only blocks

echo -e "\nChecking for read-only blocks:"
rg -U "[^\n]*ts-graphviz:read-only[^\n]*\n[\s\S]*?" --type md

This will help determine if we need to standardize the code block format across all examples


<details>
<summary>✅ Verification successful</summary>

ts[- ]graphviz' --type md

# Find read-only blocks
echo -e "\nChecking for read-only blocks:"
rg -U '```ts[- ]graphviz:read-only' --type md

# Look for any TypeScript code blocks in the docs to compare
echo -e "\nChecking for general TypeScript blocks:"
rg -U '```ts(?!.*graphviz)' --type md

'

echo -e "\nChecking content of the specific file:"
cat "i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.md"


---

After examining the file content, I can now generate a final response:

**Code block tags are used consistently and appropriately in the documentation**

The documentation follows a clear pattern where:
- The first code block uses `ts-graphviz:read-only` tag as it's the primary example demonstrating TypeScript integration
- Subsequent code blocks use regular `typescript` tags as they show different implementation approaches and don't require the read-only feature

This is intentional and correct, as the first example is meant to demonstrate IDE features (like hovering), while later examples focus on showing different API usage patterns.



</details>

<details>
<summary>🏁 Scripts executed</summary>

The following scripts were executed for the analysis:

Script:

```shell
#!/bin/bash
# Description: Check for consistency in code block usage across documentation

# Test 1: Find all ts-graphviz code blocks
echo "Checking for ts-graphviz code blocks:"
rg -U "

Length of output: 178


Script:

#!/bin/bash
# Let's try a different approach with proper escaping and simpler patterns

# Find all code blocks with ts-graphviz
echo "Checking for ts-graphviz code blocks:"
rg -U '

Length of output: 178


Script:

#!/bin/bash
# Let's try with simpler ripgrep patterns and proper string handling

echo "Checking all markdown files for code blocks:"
rg --type md -l '

Length of output: 192


Script:

#!/bin/bash
# Let's examine the specific file directly
cat "i18n/ja/docusaurus-plugin-content-docs/current/ts-graphviz/02-core-features/index.md"

Length of output: 2740

docs/ts-graphviz/02-core-features/index.md (2)

14-21: Well-structured example demonstrating TypeScript integration!

The code example effectively demonstrates:

  • Type-safe attribute usage with the attribute import
  • Clear graph construction using the declarative API
  • Proper TypeScript imports and syntax

14-15: Verify the new code block syntax implementation.

The new ts-graphviz:read-only syntax has been introduced. Let's verify that the remark plugin correctly processes this syntax.

✅ Verification successful

Let me gather more information about the remark plugin implementation to verify the syntax handling.


Let me search for the remark plugin implementation to verify the syntax handling.


Let me check the content of the remark plugin file to verify the implementation.


Based on the code inspection, I can now provide a final response:

The ts-graphviz:read-only syntax is properly implemented and supported.

The remark plugin (plugins/remark-plugin-tsgraphviz.ts) correctly handles the syntax by:

  1. Detecting code blocks with meta starting with ts-graphviz
  2. Parsing the read-only option from the meta string
  3. Transforming the code block into a TSGraphvizLiveEditor component with appropriate props
  4. The plugin is properly configured in docusaurus.config.ts for docs, blog, and pages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the remark plugin implementation for ts-graphviz:read-only syntax

# Test 1: Check if the plugin file exists and handles this syntax
rg -A 5 "ts-graphviz:read-only" 

# Test 2: Look for the plugin's syntax handling implementation
ast-grep --pattern 'ts-graphviz:read-only'

Length of output: 1245


Script:

#!/bin/bash
# Search for remark plugin files related to ts-graphviz
fd -e js -e ts remark

# Look for code block language handling in these files
rg -A 5 "lang|language.*ts-graphviz" 

# Check package.json for remark plugin configuration
cat package.json | grep -A 10 "remark"

Length of output: 329090


Script:

#!/bin/bash
# Search for remark plugin files and their content
fd -e js -e ts remark-plugin-tsgraphviz
rg -A 5 "ts-graphviz:read-only" plugins/remark-plugin-tsgraphviz.ts

Length of output: 145


Script:

#!/bin/bash
# Check the content of the remark plugin file
cat plugins/remark-plugin-tsgraphviz.ts

# Also search for any configuration in docusaurus config
rg -A 5 "remarkPlugins" docusaurus.config.ts

Length of output: 3957

@kamiazya kamiazya marked this pull request as draft November 7, 2024 16:42
@kamiazya kamiazya marked this pull request as ready for review November 7, 2024 16:46
@kamiazya
Copy link
Member Author

kamiazya commented Nov 7, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
plugins/remark-plugin-tsgraphviz.ts (3)

5-6: Consider expanding the PluginOptions type definition.

The empty PluginOptions type with a biome-ignore directive suggests future extensibility, but it might be better to define at least the basic plugin configuration options now.

Consider defining some basic options:

-// biome-ignore lint/complexity/noBannedTypes: Preliminary implementation for future extensibility.
-type PluginOptions = {};
+type PluginOptions = {
+  /** Whether to import TSGraphvizLiveEditor automatically */
+  autoImport?: boolean;
+  /** Default options for all code blocks */
+  defaults?: CodeBlockOptions;
+};

55-83: Consider making the import path configurable.

The import path '@site/src/components/TSGraphvizLiveEditor' is hardcoded in createImportNode. This might cause issues if the component location changes or if users want to provide their own editor component.

Consider making it configurable through plugin options:

-function createImportNode() {
+function createImportNode(importPath = '@site/src/components/TSGraphvizLiveEditor') {
   return {
     type: 'mdxjsEsm',
     value:
-      "import TSGraphvizLiveEditor from '@site/src/components/TSGraphvizLiveEditor'",
+      `import TSGraphvizLiveEditor from '${importPath}'`,
     // ... rest of the node creation
   };
 }

85-117: Consider optimizing the node transformation loop.

The current implementation uses a while loop with manual index management. This could be simplified using array methods.

Consider this alternative approach:

 if (isParent(node)) {
-  let index = 0;
-  while (index < node.children.length) {
-    const child = node.children[index]!;
-    if (isTSGraphvizScript(child)) {
-      const result = transformNode(child);
-      node.children.splice(index, 1, ...result);
-      index += result.length;
-      transformed = true;
-    } else {
-      index += 1;
-    }
-  }
+  const newChildren: Node[] = [];
+  node.children.forEach(child => {
+    if (isTSGraphvizScript(child)) {
+      newChildren.push(...transformNode(child));
+      transformed = true;
+    } else {
+      newChildren.push(child);
+    }
+  });
+  node.children = newChildren;
 }

This approach is more functional and easier to understand.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d3dba50 and afb1160.

📒 Files selected for processing (1)
  • plugins/remark-plugin-tsgraphviz.ts (1 hunks)
🔇 Additional comments (1)
plugins/remark-plugin-tsgraphviz.ts (1)

36-47: LGTM! Well-defined type guards.

The type guard functions are properly implemented with correct type predicates and safe null checking.

@kamiazya kamiazya merged commit 1e086e9 into main Nov 8, 2024
4 checks passed
@kamiazya kamiazya deleted the add-remark-tsgraphviz-plugin branch November 10, 2024 14:02
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.

1 participant