Markdown में Nested Lists: Indentation के वे नियम जो सच में काम करते हैं
त्वरित उत्तर
कोई nested list तभी सही से काम करती है जब उसका marker parent item के marker के बाद आने वाले पहले character से align हो — न कि जब आपने स्पेस की एक तय संख्या गिन ली हो। यही वह गलती है जो ज़्यादातर लोग करते हैं। एक dash marker (- ) की sublist को सही तरीके से nest होने के लिए सिर्फ़ 2 spaces की indentation चाहिए होती है। 10) जैसे numbered marker को 4-5 spaces चाहिए। अगर alignment गलत हो जाए, तो parser आपकी sublist को ऊपर वाले item के child की तरह नहीं, बल्कि एक नए, असंबंधित paragraph की तरह treat कर लेता है।
- Parent item
- Nested item (2 spaces — aligns with "P")
10. Parent item
- Nested item (4 spaces — aligns with "P")इस गाइड के बाकी हिस्से में alignment नियम और marker-width की गणना, वे जगहें जहाँ nesting चुपचाप फेल हो जाती है, और किसी list item के अंदर बिना structure तोड़े code block या blockquote कैसे डालें — यह सब कवर किया गया है।
चरण-दर-चरण
असली नियम: गिनना नहीं, align करना
ज़्यादातर लोग दूसरे tools से एक आदत साथ लाते हैं: "nested lists को 4 spaces से indent करो।" यह असल में John Gruber के Markdown.pl का मूल नियम है, जहाँ nesting का हर स्तर — चाहे sublist हो या continuation paragraph — एक तय 4-space या एक-tab की indentation लेता है।
CommonMark और GitHub Flavored Markdown (GFM) अलग तरीके से काम करते हैं। एक sublist को parent list marker के बाद आने वाले पहले non-whitespace character के साथ align होने के लिए indent किया जाना चाहिए, इसलिए ज़रूरी indentation तय नहीं है — यह इस पर निर्भर करती है कि parent marker कितना चौड़ा है। GFM spec इसे साफ़ शब्दों में कहता है: "list marker के बाद के text की position यह तय करती है कि उस list item के अंदर बाद के blocks में कितनी indentation चाहिए होगी।"
Marker-width की गणना करना
Parent marker के characters और उसके बाद वाले space को गिनकर indentation निकालें:
| Parent marker | Text से पहले characters | ज़रूरी sublist indent | |---|---|---| | - | 2 | 2 spaces | | * | 2 | 2 spaces | | 9. | 3 | 3 spaces | | 10. | 4 | 4 spaces | | 100. | 5 | 5 spaces |
GitHub के अपने docs इसे सीधे शब्दों में रखते हैं: 100. First list item के नीचे एक list item nest करने के लिए, child को कम-से-कम पाँच spaces indent करें — उतने ही characters जितने parent line में "First" से पहले आते हैं। एक space कम, और nested marker उस item के child जैसा नहीं दिखता।
हाथ से गणित नहीं करना चाहते? ज़्यादातर Markdown-aware editors यह आपके लिए कर देते हैं। cursor को nested line पर रखें, indent के लिए Tab और outdent के लिए Shift+Tab इस्तेमाल करें, और editor marker को सही से align कर देगा।
Unordered list के अंदर ordered list nest करना (और उल्टा भी)
चाहे किसी भी तरफ़ कोई भी list type हो, alignment का नियम वही रहता है। आप किसी bullet item के नीचे ordered list nest कर सकते हैं, या किसी numbered item के नीचे bullet sublist:
- Ingredients
1. Flour
2. Water
3. Salt
1. Steps
- Preheat the oven
- Mix the dry ingredientsदोनों ही मामलों में, child marker parent item के text के पहले character से align होता है — - को 2 spaces चाहिए, 1. को 3।
आम समस्याएँ और उनके समाधान
Nested list चुपचाप एक अलग paragraph क्यों बन जाती है
यह सबसे आम गड़बड़ी है। किसी sublist को एक space कम indent कर दें, तो error आने के बजाय, parser उसे बस एक नए top-level paragraph या एक बिल्कुल नई list की तरह render कर देता है, जो parent item से जुड़ी नहीं रहती। कोई warning नहीं मिलती — अगर आपका editor fixed-width font इस्तेमाल नहीं करता, तो Markdown आपके editor में nested दिखता रहता है, लेकिन नीचे character count गलत होता है।
समाधान हमेशा एक ही है: parent marker के characters गिनें, trailing space शामिल करके, और child line में ठीक उतने ही spaces match करें।
Parsers आपस में सहमत नहीं होते — Markdown.pl बनाम CommonMark बनाम GFM
अगर कोई nested list एक platform पर सही render होती है और दूसरी पर टूट जाती है, तो इसकी वजह आमतौर पर यह होती है कि parser किस नियम को follow करता है। Daring Fireball का मूल spec fixed 4-space convention इस्तेमाल करता है; CommonMark-आधारित parsers, जिनमें GFM भी शामिल है, इसके बजाय marker-alignment नियम इस्तेमाल करते हैं। GFM के तहत 2-space nested bullet valid है, लेकिन किसी पुराने, Markdown.pl-आधारित parser पर जो 4 spaces की उम्मीद करता है, वह nested render नहीं भी हो सकता। जब आपको यक़ीन न हो कि आपकी file किस parser से render होगी, तो marker-alignment ज़्यादा safe default है — यही CommonMark, GFM, और ज़्यादातर modern renderers लागू करते हैं।
List item के अंदर code block और blockquote डालना
किसी list item के अंदर दूसरे block types nest करने के लिए, एक साधारण sublist से एक level ज़्यादा indentation चाहिए होती है:
- Parent item
```
code fenced inside the list item, aligned with the parent text
```
> A blockquote nested inside the same item,
> with its `>` aligned to the parent text.List, code fence, और blockquote — तीनों को ऊपर "Parent item" के पहले character से align होना ज़रूरी है। यह alignment छूट जाए, तो code block या quote list item का हिस्सा होने के बजाय अलग content की तरह पढ़ा जाता है। किसी list के अंदर blockquote nest करने पर एक करीबी नज़र के लिए — जिसमें यह भी शामिल है कि callouts भी उसी तरह कैसे टूटते हैं — companion guide देखें।
Publish करने से पहले इसे पकड़ना
चूँकि टूटी हुई nesting कोई error नहीं देती, इसलिए ऐसा document publish करना आसान होता है जिसमें कोई sublist चुपचाप flat render हो रही हो। अगर आप बहुत सारा Markdown लिखते हैं, तो publish करने से पहले अपनी files को indentation की समस्याएँ पकड़ने वाले linter से गुज़ारना, सिर्फ़ visual read-through पर निर्भर रहने के बजाय, इस तरह की गलती को अपने-आप पकड़ लेता है।
अक्सर पूछे जाने वाले सवाल
Markdown में nested list के लिए कितने spaces की indentation चाहिए?
यह parent marker की चौड़ाई पर निर्भर करता है, किसी तय संख्या पर नहीं। dash या asterisk marker (- ) के लिए 2 spaces काफ़ी हैं। 10) या 100. जैसे numbered marker के लिए 4-5 spaces चाहिए। असली नियम है: nested marker को parent marker के बाद आने वाले text के पहले character से align करें।
मेरी nested list कुछ editors में क्यों टूट जाती है, बाक़ी में नहीं?
Markdown का कोई एक ही standard नहीं है। मूल Markdown.pl किसी भी nesting के लिए fixed 4-space नियम इस्तेमाल करता है। CommonMark और GitHub Flavored Markdown इसके बजाय parent marker के बाद पहले non-space character के साथ alignment की माँग करते हैं। GFM में जो 2-space indent काम करती है, वह किसी ज़्यादा strict या पुराने parser में चुपचाप फेल हो सकती है।
क्या मैं bullet list के अंदर ordered list nest कर सकता हूँ (या उल्टा)?
हाँ। Mixed nesting पूरी तरह supported है — child list (ordered या unordered) को parent item के text के पहले character से align होने के लिए indent करें, marker type चाहे जो भी हो, वही एक alignment नियम लागू होता है।
List item के अंदर code block या blockquote कैसे डालें?
इसे list item के अपने content से एक level ज़्यादा indent करें। एक indented code block को आमतौर पर 4 extra spaces चाहिए होते हैं (margin से कुल 8); triple-backtick वाला code fence बस item के text से align होना चाहिए। किसी blockquote का > भी match करने के लिए indent होना चाहिए।
Carets के साथ यह कैसे करें
Nested-list indentation को सही करना तब आसान हो जाता है जब आप वे spaces सच में देख पाते हैं जो आप टाइप कर रहे हैं। Carets, iPhone, iPad, और Mac के लिए एक native Markdown, plain text, और code editor है — आपकी files plain text ही बनी रहती हैं, तो editor में आप जो देखते हैं वही publish होता है, बिना किसी छुपे हुए auto-formatting के जो पीछे से आपकी indentation बदल दे।
Carets, Markdown और code को एक जैसे तरीके से treat करता है, तो वही syntax highlighting जो किसी code file में एक अटपटे character को पकड़ने में मदद करती है, एक लंबी nested list में marker alignment जाँचना भी आसान बना देती है। और files, projects, और tags से notes व्यवस्थित रखने के साथ, ऐसा कोई reference document — या आपकी अपनी indentation cheat sheet — अगली बार जब कोई nested list render होने से मना करे, तब भी आसानी से मिल जाता है।
iPhone, iPad, और Mac के लिए App Store से Carets पाएँ।