### Development Setup Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/README.md Commands to set up the development environment by navigating to the src directory and installing npm dependencies. ```bash cd src npm ci ``` -------------------------------- ### Example Chrome Extension ID Installation (Windows) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/agent-bridge.md An example of how to install the Agent Bridge host for a specific unpacked Chrome extension ID on Windows. ```powershell .\marksnip.exe install-host --chrome-extension-id jfmmhkkjnbhkkjnbhkkjnbhkkjnbhkkj ``` -------------------------------- ### PowerShell Pipeline Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/agent-bridge.md An example of piping the output of the MarkSnip clip command to the Set-Clipboard cmdlet in PowerShell. ```powershell .\marksnip.exe clip | Set-Clipboard ``` -------------------------------- ### Setup for Schrödinger Equation Numerical Solution in C++ Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/runjs-17-equations.md This C++ code sets up constants, a potential energy function, and a placeholder function for solving the Schrödinger equation numerically using the finite difference method for a particle in a box. It is a conceptual example and not a complete solution. ```cpp // Constantsconst hbar = 1.0545718e-34; // Reduced Planck's constant (Joule-second)const m = 9.10938356e-31; // Mass of an electron (kg) // Potential energy function V(x), assuming a particle in a box where V(x) = 0function V(x) { return 0; } // Simplified setup for the Schrödinger equation in a "particle in a box" scenariofunction solveSchrodinger(N, L) { // N: Number of points // L: Length of the box (meters) const dx = L / (N - 1); // Step size const dx2 = dx * dx; const factor = Math.pow(-hbar, 2) / (2 * m * dx2); // Initialize the wave function array and potential energy array let psi = new Array(N).fill(0); let potential = new Array(N).fill(0).map((_, i) => V(i * dx)); // Example: Finite difference method (FDM) setup (not fully implemented) // This is a placeholder to illustrate where the FDM or other numerical method would go // Return the wave function (this is a simplified placeholder) return psi; } // Example usage (this is a conceptual example and not a complete solution) const N = 100; // Number of points const L = 1e-10; // Length of the box in meters (e.g., 1 nm) const psi = solveSchrodinger(N, L); console.log(psi); // This would output the wave function array (placeholder values) ``` -------------------------------- ### Install MarkSnip Host (Windows) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/README.md Command to install the Agent Bridge host on Windows. Ensure you are in the correct directory. ```powershell cd .\native .\marksnip.exe install-host ``` -------------------------------- ### Fresh JSON Capture Example (macOS/Linux) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/agent-bridge.md Example command to capture the current browser tab's content as fresh JSON data on macOS or Linux. ```bash ./marksnip clip --json --fresh ``` -------------------------------- ### Install Native Host (Windows) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/native/README.md Installs the native host for the MarkSnip browser extension on Windows. Run this command in a PowerShell terminal. ```powershell .\marksnip.exe install-host ``` -------------------------------- ### Install MarkSnip Host (macOS/Linux) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/README.md Command to install the Agent Bridge host on macOS or Linux. Ensure you are in the correct directory. ```bash cd ./native ./marksnip install-host ``` -------------------------------- ### Install Native Host (macOS/Linux) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/native/README.md Installs the native host for the MarkSnip browser extension on macOS and Linux. Run this command in a bash terminal. ```bash ./marksnip install-host ``` -------------------------------- ### HTTP POST Request Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-pages/extension/wechat-code-block.html Example of an HTTP POST request with headers and a query string, mimicking a WeChat system interaction. ```http POST /system/user/list HTTP/1.1 Host: xxx Content-Length: 153 X-Requested-With: XMLHttpRequest pageSize=10&pageNum=1&orderByColumn=createTime ``` -------------------------------- ### Bash: Install MarkSnip Native Host Source: https://context7.com/dhruvparikh1/markdownload-extension-updated/llms.txt Installs the MarkSnip native host manifests for Chrome and Firefox. Use the --chrome-extension-id flag for local unpacked Chrome extensions. ```bash # ── First-time setup ────────────────────────────────────────────────────────── # macOS/Linux: ./marksnip install-host # Installed MarkSnip native host manifests. # Chrome manifest: /Users/alice/Application Support/Google/Chrome/NativeMessagingHosts/com.marksnip.bridge.json # Firefox manifest: /Users/alice/Application Support/Mozilla/NativeMessagingHosts/com.marksnip.bridge.json # Windows: .\marksnip.exe install-host # (also writes HKCU registry keys for Chrome and Firefox) # For a local unpacked Chrome extension (dev build): ./marksnip install-host --chrome-extension-id jfmmhkkjnbhkkjnbhkkjnbhkkjnbhkkj ``` -------------------------------- ### Full Link Reference Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example demonstrates the 'Full' link reference style, where both the link text and the URL are explicitly numbered. ```markdown [Google][1] [1]: http://google.com ``` -------------------------------- ### Custom initialization with argument conversion Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md This example shows how to redefine the `initialize` method in a Data class to handle argument conversion (e.g., string to float) and provide default values. ```php Measure = Data.define(:amount, :unit) do NONE = Data.define def initialize(amount:, unit: NONE.new) super(amount: Float(amount), unit:) end end Measure.new('10', 'km') Measure.new(10_000) ``` -------------------------------- ### Batch URL Input Examples Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/user-guide.md When adding URLs for batch processing, you can use plain URLs or Markdown link syntax. ```markdown https://example.com/page1 https://example.com/page2 [Page Title](https://example.com/page3) ``` -------------------------------- ### Original Source Image Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example shows how an image is represented using its original source URL. This is applicable when 'Image Style' is set to 'Original Source'. ```markdown ![ ](http://example.com/img/image.jpg) ``` -------------------------------- ### Base64 Encoded Image Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example shows an image encoded in Base64 format. This is used when 'Image Style' is set to 'Base64 Encoded' and 'Download Images' is enabled. ```markdown ![ ](data:image/png;base64,iVBO...) ``` -------------------------------- ### Install MarkSnip Host with Chrome Extension ID (Windows) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/README.md Installs the Agent Bridge host for a specific unpacked Chrome extension ID on Windows. Replace with the actual ID. ```powershell cd .\native .\marksnip.exe install-host --chrome-extension-id ``` -------------------------------- ### Referenced Image Reference Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example shows an image using the referenced style for image references. The image identifier is defined separately. ```markdown ![] [fig1] [fig1]: address/of/image.jpg ``` -------------------------------- ### Install Agent Bridge Host for Unpacked Chrome (Windows) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/agent-bridge.md Use this command to install the Agent Bridge host for a locally unpacked Chrome extension on Windows, specifying the extension ID. ```powershell .\marksnip.exe install-host --chrome-extension-id ``` -------------------------------- ### Install MarkSnip Host with Chrome Extension ID (macOS/Linux) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/README.md Installs the Agent Bridge host for a specific unpacked Chrome extension ID on macOS or Linux. Replace with the actual ID. ```bash cd ./native ./marksnip install-host --chrome-extension-id ``` -------------------------------- ### Install Agent Bridge Host for Unpacked Chrome (macOS/Linux) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/agent-bridge.md Use this command to install the Agent Bridge host for a locally unpacked Chrome extension on macOS or Linux, specifying the extension ID. ```bash ./marksnip install-host --chrome-extension-id ``` -------------------------------- ### Collapsed Link Reference Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example uses the 'Collapsed' link reference style, where the link text and the reference label are the same, and the URL is defined separately. ```markdown [Google][] [Google]: http://google.com ``` -------------------------------- ### Install MarkSnip Native Messaging Host Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html Run this command in your terminal to register the MarkSnip native messaging host, which is required for the Agent Bridge functionality. ```bash marksnip install-host ``` -------------------------------- ### Obsidian Internal Embed Image Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example demonstrates how an image is embedded using Obsidian's internal embed syntax. This is used when 'Image Style' is set to 'Obsidian Internal Embed'. ```markdown ![[folder/image.jpg]] ``` -------------------------------- ### Obsidian Embed Image Style Example (no folder) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example shows an Obsidian internal embed for an image located in the root of the vault. This is used when 'Image Style' is set to 'Obsidian Internal Embed' and the image is not in a subfolder. ```markdown ![[image.jpg]] ``` -------------------------------- ### Pure Markdown Image Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This example shows an image represented in pure Markdown format, typically used when 'Image Style' is set to 'Pure Markdown'. Note that this applies only if 'Download Images' is enabled. ```markdown ![ ](folder/image.jpg) ``` -------------------------------- ### Accessing Extension Options and Defaults Source: https://context7.com/dhruvparikh1/markdownload-extension-updated/llms.txt Demonstrates how to retrieve live extension options and access default configurations. Requires a browser extension context for `getOptions()`. ```javascript const { getOptions, defaultOptions } = require('./shared/default-options'); // Read live options (async — requires browser extension context): const options = await getOptions(); console.log(options.headingStyle); // "atx" console.log(options.codeBlockStyle); // "fenced" console.log(options.downloadImages); // false console.log(options.hashtagHandling); // "keep" console.log(options.tableFormatting); // { stripLinks: true, stripFormatting: false, prettyPrint: true, centerText: true } // Access defaults without storage: console.log(defaultOptions.frontmatter); // "---\ncreated: {date:YYYY-MM-DDTHH:mm:ss} (UTC {date:Z}) tags: [{keywords}] ..." console.log(defaultOptions.disallowedChars); // "[]#^" console.log(defaultOptions.imageStyle); // "markdown" console.log(defaultOptions.defaultExportType); // "markdown" ``` -------------------------------- ### Benchmark Popup Startup Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/README.md Use this script to measure popup startup performance. It measures various metrics like shell visibility, editor readiness, and content rendering. Ensure you set up a detached baseline worktree for comparison. ```bash npm run benchmark:popup -- --current "C:\path\to\repo\src" --baseline "C:\path\to\repo\.bench-baseline\src" --iterations 6 --warmup 1 ``` -------------------------------- ### JavaScript Navier-Stokes Simulation Structure Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/runjs-17-equations.md This code provides a foundational structure for simulating fluid dynamics using a simplified approach to the Navier-Stokes equations. It includes parameter setup, field initialization, and placeholder functions for derivative calculations and updates. Use this as a starting point for understanding the numerical methods involved. ```javascript // Parametersconst nx = 20; // Number of grid points in x directionconst ny = 20; // Number of grid points in y directionconst nu = 0.01; // Kinematic viscosityconst dt = 0.1; // Time stepconst rho = 1.0; // Density, assuming constant // Initialize velocity and pressure fieldsconst u = new Array(ny).fill(0).map(() => new Array(nx).fill(0));const v = new Array(ny).fill(0).map(() => new Array(nx).fill(0));const p = new Array(ny).fill(0).map(() => new Array(nx).fill(0)); // Function to approximate the first derivatives using central differencefunction derivative(arr, dx, axis) { const result = new Array(arr.length) .fill(0) .map(() => new Array(arr[0].length).fill(0)); for (let i = 1; i < arr.length - 1; i++) { for (let j = 1; j < arr[i].length - 1; j++) { if (axis === "x") { result[i][j] = (arr[i][j + 1] - arr[i][j - 1]) / (2 * dx); } else if (axis === "y") { result[i][j] = (arr[i + 1][j] - arr[i - 1][j]) / (2 * dx); } } } return result; } // Function to approximate the second derivatives using central differencefunction secondDerivative(arr, dx) { // Similar to derivative function but for second derivatives // This is a placeholder; implementation would be similar to the first derivative } // Main update function (simplified and not fully accurate)function updateVelocity(u, v, p, nu, dt, dx, dy) { // Calculate derivatives const uxx = secondDerivative(u, dx); const uyy = secondDerivative(u, dy); const vxx = secondDerivative(v, dx); const vyy = secondDerivative(v, dy); const ux = derivative(u, dx, "x"); const uy = derivative(u, dy, "y"); const vx = derivative(v, dx, "x"); const vy = derivative(v, dy, "y"); const px = derivative(p, dx, "x"); const py = derivative(p, dy, "y"); // Update velocities (simplified Euler integration) for (let i = 1; i < ny - 1; i++) { for (let j = 1; j < nx - 1; j++) { u[i][j] -= dt * (u[i][j] * ux[i][j] + v[i][j] * uy[i][j] + px[i][j] / rho + nu * (uxx[i][j] + uyy[i][j])); v[i][j] -= dt * (u[i][j] * vx[i][j] + v[i][j] * vy[i][j] + py[i][j] / rho + nu * (vxx[i][j] + vyy[i][j])); } } } // Placeholder function for pressure calculation // Real implementation would solve the pressure Poisson equationfunction updatePressure(p, u, v, dx, dy) { // This is a placeholder; actual implementation is complex } // Example of running an updateupdateVelocity(u, v, p, nu, dt, 1.0 / nx, 1.0 / ny); ``` -------------------------------- ### Build Native Host Companion Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/README.md Compile the Agent Bridge companion binaries using Go. Ensure you are in the `native/` directory. ```bash go build ./cmd/marksnip ``` ```bash go build ./cmd/marksnip-native-host ``` -------------------------------- ### Referenced Link Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This is an example of a referenced link. The link text is separate from the URL, which is defined elsewhere in the document. ```markdown [Google] [Google]: http://google.com ``` -------------------------------- ### Inlined Link Style Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This is an example of an inlined link. The link text and URL are placed directly within the Markdown. ```markdown [Google](http://google.com) ``` -------------------------------- ### Fenced Code Block Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This is an example of a fenced code block. It is used when the 'Fenced' option is selected for code block formatting. ```javascript ``` const helloWorld = () => { ····console.log("Hello World"); } ``` ``` -------------------------------- ### Indented Code Block Example Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/options/options.html This is an example of an indented code block. It is used when the 'Indented' option is selected for code block formatting. ```javascript ····const helloWorld = () => { ········console.log("Hello World"); ····} ``` -------------------------------- ### MarkSnip Build and Development Scripts Source: https://context7.com/dhruvparikh1/markdownload-extension-updated/llms.txt Common npm scripts for building, testing, and packaging the MarkSnip extension. Run these commands from the `src/` directory. ```bash cd src npm ci # Install dependencies npm test # Run full test suite (unit + integration + e2e) npm run test:unit # Jest unit tests only npm run test:integration # Jest integration tests only npm run test:e2e # Playwright end-to-end tests npm run build:manifests # Generate .build/chrome/ and .build/firefox/ manifests npm run build # Firefox .xpi via web-ext npm run build:chrome # Chrome .zip package npm run build:all # Both Firefox and Chrome artifacts # Load the unpacked extension in Chrome (after build:manifests): # 1. Open chrome://extensions # 2. Enable Developer mode # 3. Click "Load unpacked" → select src/.build/chrome ``` ```bash # Agent Bridge (from native/): cd ../native go build ./cmd/marksnip go build ./cmd/marksnip-native-host ``` ```powershell # Find unpacked Chrome extension ID on Windows: powershell -ExecutionPolicy Bypass -File .\tools\find-unpacked-chrome-extension-id.ps1 -ExtensionPath .\src ``` -------------------------------- ### Ruby Data Class Initialization (C Implementation) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md This C code snippet illustrates the underlying implementation of the `initialize` method for Ruby Data classes, handling keyword arguments, missing arguments, and unknown keywords. ```objectivec static VALUE rb_data_initialize_m(int argc, const VALUE *argv, VALUE self) { VALUE klass = rb_obj_class(self); rb_struct_modify(self); VALUE members = struct_ivar_get(klass, id_members); size_t num_members = RARRAY_LEN(members); if (argc == 0) { if (num_members > 0) { rb_exc_raise(rb_keyword_error_new("missing", members)); } return Qnil; } if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) { rb_error_arity(argc, 0, 0); } if (RHASH_SIZE(argv[0]) < num_members) { VALUE missing = rb_ary_diff(members, rb_hash_keys(argv[0])); rb_exc_raise(rb_keyword_error_new("missing", missing)); } struct struct_hash_set_arg arg; rb_mem_clear((VALUE *)RSTRUCT_CONST_PTR(self), num_members); arg.self = self; arg.unknown_keywords = Qnil; rb_hash_foreach(argv[0], struct_hash_set_i, (VALUE)&arg); // Freeze early before potentially raising, so that we don't leave an // unfrozen copy on the heap, which could get exposed via ObjectSpace. OBJ_FREEZE_RAW(self); if (arg.unknown_keywords != Qnil) { rb_exc_raise(rb_keyword_error_new("unknown", arg.unknown_keywords)); } return Qnil; } ``` -------------------------------- ### Agent Bridge Quick Reference (Windows) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/agent-bridge.md A consolidated list of common Agent Bridge commands for Windows. ```powershell .\marksnip.exe install-host .\marksnip.exe status .\marksnip.exe clip .\marksnip.exe clip --json .\marksnip.exe clip --fresh .\marksnip.exe uninstall-host ``` -------------------------------- ### Agent Bridge Quick Reference (macOS/Linux) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/docs/guides/agent-bridge.md A consolidated list of common Agent Bridge commands for macOS and Linux. ```bash ./marksnip install-host ./marksnip status ./marksnip clip ./marksnip clip --json ./marksnip clip --fresh ./marksnip uninstall-host ``` -------------------------------- ### Create Turndown Service with GFM and Custom Rules Source: https://context7.com/dhruvparikh1/markdownload-extension-updated/llms.txt Instantiates a Turndown service with GitHub Flavored Markdown extensions and custom rules for specific HTML tags. Useful for advanced HTML to Markdown conversion. Dependency injection is supported for testing. ```javascript const { createTurndownService } = require('./shared/turndown-factory'); const { service } = createTurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced', fence: '```', linkStyle: 'inlined', strongDelimiter: '**', emDelimiter: '_', turndownEscape: true, }, { TurndownService: globalThis.TurndownService, turndownPluginGfm: globalThis.turndownPluginGfm, mathMLApi: globalThis.MarkSnipMathML, }); const html = `

Hello World

A bold and italic paragraph.

console.log("hi")
NameScore
Alice99
`; const markdown = service.turndown(html); // => "# Hello World\n\nA **bold** and _italic_ paragraph.\n\n```js\nconsole.log(\"hi\")\n```\n\n| Name | Score |\n| ----- | ----- |\n| Alice | 99 |\n" ``` -------------------------------- ### Get String Representation of Data Object Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md The `inspect` method returns a string representation of the Data object, useful for debugging and logging. ```makefile Measure = Data.define(:amount, :unit) distance = Measure[10, 'km'] p distance puts distance ``` -------------------------------- ### Get Member Names of Data Object Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md The `members` method returns an array of symbols representing the names of the members defined in the Data object. ```makefile Measure = Data.define(:amount, :unit) distance = Measure[10, 'km'] distance.members ``` -------------------------------- ### Resolve Site Rule Options with URL Patterns Source: https://context7.com/dhruvparikh1/markdownload-extension-updated/llms.txt Use `resolveSiteRuleOptions` to apply site-specific configurations based on URL patterns. Supports wildcard matching for host and path segments. Ensure `siteRules` are normalized before use. ```javascript const { resolveSiteRuleOptions, matchesSiteRulePattern, normalizeSiteRules, } = require('./shared/site-rules'); const baseOptions = { includeTemplate: false, imageStyle: 'markdown', downloadImages: false, tableFormatting: { stripLinks: true, prettyPrint: true }, siteRules: [ { id: 'github-rule', name: 'GitHub', enabled: true, pattern: 'github.com/*', overrides: { includeTemplate: true, imageStyle: 'originalSource', tableFormatting: { stripFormatting: true } } }, { id: 'docs-rule', name: 'Docs sites', enabled: true, pattern: '*.readthedocs.io/*', overrides: { mdClipsFolder: 'docs/{date:YYYY-MM-DD}' } } ] }; // Resolves for a GitHub URL: const { options, matchedRule, overriddenKeys } = resolveSiteRuleOptions( 'https://github.com/user/repo/blob/main/README.md', baseOptions ); console.log(matchedRule?.name); // "GitHub" console.log(overriddenKeys); // ["includeTemplate", "imageStyle", "tableFormatting.stripFormatting"] console.log(options.includeTemplate); // true console.log(options.imageStyle); // "originalSource" // Pattern matching only: matchesSiteRulePattern('*.example.com/blog/*', 'https://news.example.com/blog/post-1'); // => true matchesSiteRulePattern('https://example.com/*', 'http://example.com/page'); // => false (scheme mismatch) // Normalise raw rule objects from storage: normalizeSiteRules([{ pattern: 'example.com/*', overrides: { downloadImages: true } }]); // => [{ id: 'site-rule-1', name: 'Site Rule 1', enabled: true, pattern: 'example.com/*', // overrides: { downloadImages: true } }] ``` -------------------------------- ### Get members of a Data class Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md The `members` method returns an array of symbols representing the names of the members defined in a Data class. This is useful for introspection. ```makefile Measure = Data.define(:amount, :unit) Measure.members ``` -------------------------------- ### C Implementation for Ruby Instance Method with Keyword Arguments Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md This C code implements a Ruby instance method that handles keyword arguments. It parses arguments, updates a hash, and creates a new instance of the object's class with the updated hash. ```c static VALUE rb_data_with(int argc, const VALUE *argv, VALUE self) { VALUE kwargs; rb_scan_args(argc, argv, "0:", &kwargs); if (NIL_P(kwargs)) { return self; } VALUE h = rb_struct_to_h(self); rb_hash_update_by(h, kwargs, 0); return rb_class_new_instance_kw(1, &h, rb_obj_class(self), TRUE); } ``` -------------------------------- ### Constructors for Data classes Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md Data classes defined with `Data.define` accept both positional and keyword arguments for instantiation via `.new` or `[]`. All arguments are mandatory. ```csharp Measure = Data.define(:amount, :unit) Measure.new(1, 'km') Measure.new(amount: 1, unit: 'km') Measure[1, 'km'] Measure[amount: 1, unit: 'km'] ``` -------------------------------- ### Create a Copy with Updated Fields Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md The `with` method returns a shallow copy of the Data object, with specified fields updated to new values. It raises an error if an unknown member name is provided. ```makefile ``` -------------------------------- ### Creating and Modifying Data Structs in Ruby Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md Demonstrates the creation of a 'Point' data struct and its modification using the 'with' method to create new instances with updated values. Note that 'with' can also accept positional arguments. ```ruby Point = Data.define(:x, :y) origin = Point.new(x: 0, y: 0) up = origin.with(x: 1) right = origin.with(y: 1) up_and_right = up.with(y: 1) p origin p up p right p up_and_right out = origin.with(z: 1) some_point = origin.with(1, 2) ``` -------------------------------- ### Uninstall MarkSnip Host Source: https://context7.com/dhruvparikh1/markdownload-extension-updated/llms.txt Command to remove MarkSnip manifests and registry keys. Ensure you are in the project root directory. ```bash ./marksnip uninstall-host # (removes manifests and registry keys) ``` -------------------------------- ### with(**kwargs) Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md Returns a shallow copy of the Data object. If keyword arguments are provided, the copy will have the respective field values updated. ```APIDOC ## with(**kwargs) ### Description Returns a shallow copy of `self` — the instance variables of `self` are copied, but not the objects they reference. If the method is supplied any keyword arguments, the copy will be created with the respective field values updated to use the supplied keyword argument values. Note that it is an error to supply a keyword that the [`Data`](https://ruby-doc.org/3.3.6/Data.html) class does not have as a member. ### Examples: ```makefile ``` -------------------------------- ### Add Custom Methods and Comparability Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md Define additional methods within the `Data.define` block, such as comparison operators. Include the `Comparable` module to enable standard comparison methods. Note that comparisons may fail if units do not match. ```ruby Measure = Data.define(:amount, :unit) do def <=>(other) return unless other.is_a?(self.class) && other.unit == unit amount <=> other.amount end include Comparable end Measure[3, 'm'] < Measure[5, 'm'] Measure[3, 'm'] < Measure[5, 'kg'] ``` -------------------------------- ### Mandatory arguments and initialization Source: https://github.com/dhruvparikh1/markdownload-extension-updated/blob/main/src/tests/fixtures/e2e-markdown/ruby-doc-3.3.6-data.md Arguments for `Data.define` are mandatory and checked during initialization. Redefining `initialize` allows for argument conversion or default value assignment. ```csharp Measure.new(amount: 1) Measure.new(1) ```