Debian Codegraph @

.github/copilot-instructions.md

raw symbols SCIP
1 # RDiscount — Copilot Instructions
2
3 ## Project Overview
4
5 RDiscount is a Ruby C extension wrapping David Parsons' [Discount](https://www.pell.portland.or.us/~orc/Code/discount/) Markdown library. It provides fast Markdown-to-HTML conversion from Ruby.
6
7 - **Ruby API**: `lib/rdiscount.rb`, `lib/markdown.rb`
8 - **C bridge**: `ext/rdiscount.c` (Ruby ↔ Discount glue, ~150 LOC)
9 - **Discount sources**: `ext/*.c`, `ext/*.h` (copied from `discount/` submodule via `rake gather`)
10 - **Tests**: `test/rdiscount_test.rb`, `test/markdown_test.rb`, plus conformance suites in `test/MarkdownTest_1.0*/`
11
12 ## Build & Test
13
14 ```bash
15 # Build the C extension
16 rake build
17
18 # Run all tests (unit + conformance)
19 rake test
20
21 # Unit tests only
22 rake test:unit
23
24 # Conformance tests (Markdown spec 1.0.3)
25 rake test:conformance
26 ```
27
28 ## Architecture
29
30 ```
31 discount/ ← Git submodule (upstream Discount C library)
32 ext/ ← C extension: Discount sources + rdiscount.c bridge + extconf.rb
33 rdiscount.c ← Ruby-C bridge (do NOT overwrite during gather)
34 extconf.rb ← mkmf build config (do NOT overwrite during gather)
35 config.h ← RDiscount-specific (do NOT overwrite during gather)
36 lib/
37 rdiscount.rb ← Ruby API class, VERSION constant (single source of truth)
38 markdown.rb ← BlueCloth compatibility alias
39 test/ ← Test::Unit tests + MarkdownTest conformance suites
40 ext.diff ← Patches applied to Discount sources in ext/ after copying
41 ```
42
43 ### How Discount sources flow into ext/
44
45 1. `git submodule update --init` fetches `discount/`
46 2. `cd discount && ./configure.sh` generates config
47 3. `rake gather` copies `*.c`, `*.h` from `discount/` → `ext/` (skipping files with `main()` and RDiscount-specific files)
48 4. `ext.diff` is applied via `patch -p1 -d ext`
49
50 See [BUILDING](../BUILDING) for the full upgrade procedure.
51
52 ## Key Conventions
53
54 - **Version**: Single source of truth is `VERSION` constant in `lib/rdiscount.rb`. The gemspec extracts it automatically.
55 - **Testing pattern**: Create `RDiscount.new(text, *flags)`, call `.to_html`, assert output HTML.
56 - **Locale**: The C bridge sets `LC_CTYPE=C` during processing for consistent ASCII behavior regardless of Ruby's UTF-8 locale.
57 - **Default flags**: Always enabled: `MKD_TABSTOP | MKD_NOHEADER | MKD_DLEXTRA | MKD_FENCEDCODE | MKD_GITHUBTAGS`.
58 - **Flag mapping**: Ruby boolean accessors (e.g., `:smart`, `:autolink`) map to Discount C flags in the `ACCESSOR_2_FLAG[]` array in `ext/rdiscount.c`.
59
60 ## Files You Should NOT Edit Directly
61
62 The following files in `ext/` are **copied from discount/** by `rake gather` and will be overwritten:
63 - All `*.c` and `*.h` files EXCEPT `rdiscount.c`, `extconf.rb`, `config.h`, `ruby-config.h`
64
65 To make persistent changes to Discount sources, update `ext.diff` instead.
66
67 ## Release Process
68
69 1. Update `VERSION` in `lib/rdiscount.rb`
70 2. `rake rdiscount.gemspec` — regenerates file manifest
71 3. `rake test` — verify all tests pass
72 4. `gem build rdiscount.gemspec`
73 5. `gem push rdiscount-X.Y.Z.gem`