Configurable codegen highlight language and file extension

This commit is contained in:
Ankit Mahato
2023-07-20 02:59:20 +05:30
parent bab08769e7
commit e77747df30
2 changed files with 7 additions and 5 deletions

View File

@ -230,11 +230,13 @@ const kDefaultHttpMethod = HTTPVerb.get;
const kDefaultContentType = ContentType.json; const kDefaultContentType = ContentType.json;
enum CodegenLanguage { enum CodegenLanguage {
dartHttp("Dart (http)"), dartHttp("Dart (http)", "dart", "dart"),
kotlinOkHttp("Kotlin (OkHttp)"); kotlinOkHttp("Kotlin (OkHttp)", "java", "kt");
const CodegenLanguage(this.label); const CodegenLanguage(this.label, this.codeHighlightLang, this.ext);
final String label; final String label;
final String codeHighlightLang;
final String ext;
} }
const JsonEncoder kEncoder = JsonEncoder.withIndent(' '); const JsonEncoder kEncoder = JsonEncoder.withIndent(' ');

View File

@ -160,7 +160,7 @@ class _ViewCodePaneState extends State<ViewCodePane> {
), ),
SaveInDownloadsButton( SaveInDownloadsButton(
content: stringToBytes(widget.code), content: stringToBytes(widget.code),
mimeType: "application/vnd.dart", ext: widget.codegenLanguage.ext,
showLabel: showLabel, showLabel: showLabel,
) )
], ],
@ -175,7 +175,7 @@ class _ViewCodePaneState extends State<ViewCodePane> {
child: CodeGenPreviewer( child: CodeGenPreviewer(
code: widget.code, code: widget.code,
theme: codeTheme, theme: codeTheme,
language: 'dart', language: widget.codegenLanguage.codeHighlightLang,
textStyle: kCodeStyle, textStyle: kCodeStyle,
), ),
), ),