mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix indent for docgen
This commit is contained in:
parent
d582a42e0f
commit
9633b7a3cc
@ -11,6 +11,7 @@ git config --add core.filemode false
|
||||
chmod +x *.sh
|
||||
sh update-compiler.sh
|
||||
chmod +x package/pikascript/rust-msc-latest-linux
|
||||
cp package/pikascript/rust-msc-latest-linux /bin
|
||||
cd package/pikascript/pikascript-core
|
||||
# git checkout master
|
||||
cd $ROOT
|
||||
|
@ -3215,21 +3215,28 @@ static char* _parser_fixDocStringIndent(Parser* self,
|
||||
char* sBuff = strsCopy(&self->lineBuffs, sDocString);
|
||||
Arg* aOut = arg_newStr("");
|
||||
char* sOut = NULL;
|
||||
int bGetIndent = 0;
|
||||
uint32_t iLineNum = strCountSign(sBuff, '\n');
|
||||
int indentThis = 0;
|
||||
for (int i = 0; i < iLineNum; i++) {
|
||||
char* sLine = strsPopToken(&self->lineBuffs, &sBuff, '\n');
|
||||
if (i == 0) {
|
||||
indentThis = strGetInedent(sLine);
|
||||
if (strIsBlank(sLine)) {
|
||||
continue;
|
||||
}
|
||||
if (strGetInedent(sLine) >= indentThis) {
|
||||
sLine = sLine + indentThis;
|
||||
if (!bGetIndent) {
|
||||
bGetIndent = 1;
|
||||
indentThis = strGetIndent(sLine);
|
||||
}
|
||||
for (int k = 0; k < indent; k++) {
|
||||
aOut = arg_strAppend(aOut, " ");
|
||||
if (bGetIndent) {
|
||||
if (strGetIndent(sLine) >= indentThis) {
|
||||
sLine = sLine + indentThis;
|
||||
}
|
||||
for (int k = 0; k < indent; k++) {
|
||||
aOut = arg_strAppend(aOut, " ");
|
||||
}
|
||||
aOut = arg_strAppend(aOut, sLine);
|
||||
aOut = arg_strAppend(aOut, "\n");
|
||||
}
|
||||
aOut = arg_strAppend(aOut, sLine);
|
||||
aOut = arg_strAppend(aOut, "\n");
|
||||
}
|
||||
sOut = strsCopy(&self->lineBuffs, arg_getStr(aOut));
|
||||
arg_deinit(aOut);
|
||||
|
@ -380,7 +380,7 @@ int strPathGetFileName(char* input, char* output) {
|
||||
return i - j - 1;
|
||||
}
|
||||
|
||||
int strGetInedent(char* string) {
|
||||
int strGetIndent(char* string) {
|
||||
int indent = 0;
|
||||
int len = strGetSize(string);
|
||||
for (int j = 0; j < len; j++) {
|
||||
@ -392,3 +392,14 @@ int strGetInedent(char* string) {
|
||||
}
|
||||
return indent;
|
||||
}
|
||||
|
||||
int strIsBlank(char* string) {
|
||||
int len = strGetSize(string);
|
||||
for (int j = 0; j < len; j++) {
|
||||
if (string[j] != ' ' && string[j] != '\t' && string[j] != '\r' &&
|
||||
string[j] != '\n') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ int strPathFormat(char* input, char* output);
|
||||
int strPathJoin(char* input1, char* input2, char* output);
|
||||
int strPathGetFolder(char* input, char* output);
|
||||
int strPathGetFileName(char* input, char* output);
|
||||
int strGetInedent(char* string);
|
||||
int strGetIndent(char* string);
|
||||
int strIsBlank(char* string);
|
||||
|
||||
#endif
|
||||
|
@ -57,6 +57,7 @@ TEST_FILE2DOCFILE(configparser,
|
||||
"test/out/configparser.md")
|
||||
|
||||
TEST_FILE2DOCFILE(mqtt_file, "package/pikascript/mqtt.py", "test/out/mqtt.md")
|
||||
TEST_FILE2DOCFILE(requests_file, "package/pikascript/requests.py", "test/out/requests.md")
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user