Indentation of multi-line values in text templates
- Dominant language
- Objective-C
- Stars
- 1.4k
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
Hi Gwendal
What is the best approach for trying to preserve newline formatting and indentation when processing text (as opposed to HTML) templates?
As a practical example consider the following text template that generates a C file to echo its inputs:
```
#include
int main(int argc, char *argv[])
{
{{ task-input-variables }}
{{ task-input-result }}
return 0;
}
```
The minimal template variable dict for this is:
```
{
"task-input-result" : "\t\/\/ Return inputs as task result\n\tprintf(\"%s\\n\", taskInput1);\n\tprintf(\"%s\\n\", taskInput2);\n\t",
"task-input-variables" : "\t\/\/ Task input variables \n\tchar *taskInput1 = argv[1];\n\tchar *taskInput2 = argv[2];\n"
}
```
The output is :
```
#include
int main(int argc, char *argv[])
{
// Task input variables
char *taskInput1 = argv[1];
char *taskInput2 = argv[2];
// Return inputs as task result
printf("%s\n", taskInput1);
printf("%s\n", taskInput2);
return 0;
}
```
So the above works. However the issues are that I have pre-empt indentation and new line creation. So I have to embed tabs in my variables (otherwise only the first line of say `{{ task-input-variables }}` will be indented) which is less than desirable. What this boils down to is that I would like to be able to format my template as below while maintaining the final rendering shown above.
```
#include
int main(int argc, char *argv[])
{
{{ task-input-variables }}
{{ task-input-result }}
return 0;
}
```
Any thoughts?
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the issue examples and its 11-comment thread first; no implementation file or test is named. Trace the text-template rendering entry point and define done as applying template indentation to every line of a multiline value while preserving the shown C output.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100