LMS.ExtractCodeBlock - Extract Code Block

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > LMS. - LM-Studio Commands > NEW: LMS v2.1 Commands - Model Query, Status, and Text Extraction >

LMS.ExtractCodeBlock - Extract Code Block

Extracts code content from markdown code blocks (```). Useful for getting clean code from AI responses that include markdown formatting.

Syntax:

LMS.ExtractCodeBlock|$$SOURCE|$$LANG|$$BLOCKNUM|$$RET_VAR

Parameters:

$$SOURCE (String, required) - Source text containing code blocks.

$$LANG (String, required) - Language filter (e.g., "json", "basic", "" for any).

$$BLOCKNUM (Number, required) - Which block to extract (1=first, 2=second, etc.).

$$RET_VAR (Variable, required) - Variable to receive extracted code.

Examples:

; Extract first JSON code block

LMS.ask|"Give me JSON with user data"|response

LMS.ExtractCodeBlock|response|json|1|jsonCode

; jsonCode now contains clean JSON without ```json markers

See Also:

LMS.ExtractCleanAnswerLMS.ExtractXmlTag